EXTRACT/de

From SQLZOO
Jump to navigation Jump to search
Kompatibilität
EXTRACT(YEAR FROM d)
DBMSOKAlternative
IngresJa
MySQLJa YEAR(d)
OracleJa TO_CHAR(d,'YYYY')
PostgreSQLJa YEAR(d)
SQL ServerNein DATEPART(YEAR, d)

EXTRACT

EXTRACT ermittelt Bestandteile eines Datumswertes.

Folgende Werte können ermittelt werden: Jahr (YEAR), Monat (MONTH), Tag (DAY), Stunde (HOUR), Minute (MINUTE), Sekunde (SECOND).

  EXTRACT(YEAR FROM d)    EXTRACT(MONTH FROM d)
  EXTRACT(DAY FROM d)     EXTRACT(HOUR FROM d)
  EXTRACT(MINUTE FROM d)  EXTRACT(SECOND FROM d)

In diesem Beispiel werden das Jahr und die Stunde aus dem whn-Datum ermittelt.

SELECT whn
      ,DATEPART(YEAR, whn)  AS yr
      ,DATEPART(HOUR, whn) AS hr
  FROM eclipse
SELECT whn
      ,EXTRACT(YEAR FROM td)  AS yr
      ,EXTRACT(HOUR FROM td) AS hr
  FROM gisq.eclipse
SELECT whn
      ,EXTRACT(YEAR FROM td)  AS yr
      ,EXTRACT(HOUR FROM td) AS hr
  FROM eclipse

Siehe auch

Language:Project:Language policy [[:{{#invoke:String|sub|EXTRACT/de
 |1
 |Expression error: Unrecognized punctuation character "{".
}}|English]]
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects