QUARTER

From SQLZOO
Revision as of 12:54, 16 July 2012 by Connor (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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.

December 31</td>

</table>

   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 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

Personal tools
Namespaces

Variants
Actions
Google AdSense
QUARTERS
First QuarterJanuary 1March 31
Second QuarterApril 1June 30
Third QuarterJuly 1September 30
Fourth QuarterOctober 1