Difference between revisions of "QUARTER"

From SQLZOO
Jump to: navigation, search
 
Line 69: Line 69:
 
   <li>[[MONTH |MONTH function]]</li>
 
   <li>[[MONTH |MONTH function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 21:25, 21 October 2012

Compatibility
QUARTER(d)
EngineOKAlternative
ingresYesEXTRACT(QUARTER from d)
mysqlYesEXTRACT(QUARTER from d)
oracleNoTO_CHAR(d,'Q')
postgresNoEXTRACT(QUARTER from d)
sqlserverNoDATEPART(QUARTER,d)

QUARTER

QUARTER allows you to retrieve the 3 month period from a date.

QUARTERS
First QuarterJanuary 1March 31
Second QuarterApril 1June 30
Third QuarterJuly 1September 30
Fourth QuarterOctober 1December 31
   QUARTER(d)

In this example you get the quarter from the date field wk. Lately, Cliff Richard favours Q4.

SELECT wk,
       EXTRACT(QUARTER FROM wk) AS Quarter,
       song
  FROM totp
 WHERE singer = 'Cliff Richard'
 ORDER BY wk DESC
SELECT wk,
       TO_CHAR(wk,'QUARTER') AS Quarter,
       song
  FROM gisq.totp
 WHERE singer = 'Cliff Richard'
 ORDER BY wk DESC
SELECT wk,
       DATEPART(QUARTER,wk) AS Quarter,
       song
  FROM totp
 WHERE singer = 'Cliff Richard'
 ORDER BY wk DESC
SELECT wk,
       QUARTER(wk) AS Quarter,
       song
  FROM totp
 WHERE singer = 'Cliff Richard'
 ORDER BY wk DESC

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense