Das folgende Oracle-SQL gruppiert die fehlgeschlagenen Datensätze aus der Tabelle
'tabelle_mit_datum'
nach Jahr, Monat und Tag:
SELECT
COUNT(*) AnzahlFehler,
TO_CHAR(cs.datum, 'YYYY') Jahr,
TO_CHAR(cs.datum, 'MM') Monat,
TO_CHAR(cs.datum, 'DD') Tag,
FROM
tabelle_mit_datum tmd
WHERE
tmd.status = 'Fehler'
AND tmd.datum BETWEEN
TO_DATE('01.01.2017', 'DD.MM.YYYY')
AND TO_DATE('30.04.2017', 'DD.MM.YYYY')
GROUP BY
TO_CHAR(cs.datum, 'YYYY') Jahr,
TO_CHAR(cs.datum, 'MM') Monat,
TO_CHAR(cs.datum, 'DD') Tag,
ORDER BY
TO_CHAR(cs.datum, 'YYYY') Jahr DESC,
TO_CHAR(cs.datum, 'MM') Monat DESC,
TO_CHAR(cs.datum, 'DD') Tag DESC
;
Oracles
TO_CHAR(date, dateformat)
Funktion kann einige tolle Sachen. Der folgende Ausdruck liefert die Woche des Jahres zurück:
SELECT TO_CHAR(sysdate, 'IW') FROM dual;
Folgende Formate stehen als Parameter zur Verfügung:
YEAR | Year, spelled out |
YYYY | 4-digit year |
YYY | Last 3 digits of year. |
YY | Last 2 digits of year. |
Y | Last digit of year. |
IYY | Last 3 digits of ISO year. |
IY | Last 2 digits of ISO year. |
I | Last 1 digit of ISO year. |
IYYY | 4-digit year based on the ISO standard |
Q | Quarter of year (1, 2, 3, 4; JAN-MAR = 1). |
MM | Month (01-12; JAN = 01). |
MON | Abbreviated name of month. |
MONTH | Name of month, padded with blanks to length of 9 characters. |
RM | Roman numeral month (I-XII; JAN = I). |
WW | Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year. |
W | Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. |
IW | Week of year (1-52 or 1-53) based on the ISO standard. |
D | Day of week (1-7). |
DAY | Name of day. |
DD | Day of month (1-31). |
DDD | Day of year (1-366). |
DY | Abbreviated name of day. |
J | Julian day; the number of days since January 1, 4712 BC. |
HH | Hour of day (1-12). |
HH12 | Hour of day (1-12). |
HH24 | Hour of day (0-23). |
MI | Minute (0-59). |
SS | Second (0-59). |
SSSSS | Seconds past midnight (0-86399). |
FF | Fractional seconds. |
Keine Kommentare:
Kommentar veröffentlichen