QUARTER

From SQLZoo
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:Project:Language policy English  • Deutsch
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects
  • Your server today is: Dipsy