Difference between revisions of "QUARTER"

From SQLZOO
Jump to: navigation, search
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>QUARTER(d)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''<...")
 
Line 17: Line 17:
 
<tr><td align='left'>Second Quarter</td><td align='left'>April 1</td><td>June 30</td></tr>
 
<tr><td align='left'>Second Quarter</td><td align='left'>April 1</td><td>June 30</td></tr>
 
<tr><td align='left'>Third Quarter</td><td align='left'>July 1</td><td>September 30</td></tr>
 
<tr><td align='left'>Third Quarter</td><td align='left'>July 1</td><td>September 30</td></tr>
<tr><td align='left'>Fourth Quarter</td><td align='left'>October 1</td>December 31</td></tr>
+
<tr><td align='left'>Fourth Quarter</td><td align='left'>October 1</td><td>December 31</td></tr>
 
</table>
 
</table>
 
<pre style='width:60ex'>
 
<pre style='width:60ex'>

Revision as of 11:56, 16 July 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 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
Reference
Toolbox
Google AdSense