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'''<...")
 
 
(2 intermediate revisions by one user not shown)
Line 5: Line 5:
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
 
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
 
<tr><td align='left'>mysql</td><td>Yes</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(d,'Q')]]</td></tr>
+
<tr><td align='left'>oracle</td><td>No</td><td>[[TO_CHAR(dates) |TO_CHAR(d,'Q')]]</td></tr>
 
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
 
<tr><td align='left'>postgres</td><td>No</td><td>[[EXTRACT |EXTRACT(QUARTER from d)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[DATEPART |DATEPART(QUARTER,d)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[DATEPART |DATEPART(QUARTER,d)]]</td></tr>
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'>
Line 37: Line 37:
 
       TO_CHAR(wk,'QUARTER') AS Quarter,
 
       TO_CHAR(wk,'QUARTER') AS Quarter,
 
       song
 
       song
   FROM totp
+
   FROM gisq.totp
 
  WHERE singer = 'Cliff Richard'
 
  WHERE singer = 'Cliff Richard'
 
  ORDER BY wk DESC
 
  ORDER BY wk DESC
Line 62: Line 62:
 
<ul>
 
<ul>
 
   <li>[[EXTRACT |EXTRACT function]]</li>
 
   <li>[[EXTRACT |EXTRACT function]]</li>
   <li>[[ +(date) function]]</li>
+
   <li>[[%2B(dates) |+(date) function]]</li>
 
   <li>[[HOUR |HOUR function]]</li>
 
   <li>[[HOUR |HOUR function]]</li>
 
   <li>[[MINUTE |MINUTE function]]</li>
 
   <li>[[MINUTE |MINUTE function]]</li>
 
   <li>[[DAY |DAY function]]</li>
 
   <li>[[DAY |DAY function]]</li>
   <li>[[SECOND function]]</li>
+
   <li>[[SECOND |SECOND function]]</li>
 
   <li>[[MONTH |MONTH function]]</li>
 
   <li>[[MONTH |MONTH function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 22: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