SELECT End_Tran_Time AS order_date,
SUM ( (CASE WHEN Hour = '18'and MIN < '30' THEN 1 ELSE 0 END)) AS "18",
SUM ( (CASE WHEN Hour = '18'and MIN > '31' THEN 1 ELSE 0 END)) AS "18.5",
SUM ( (CASE WHEN Hour = '19'and MIN < '30' THEN 1 ELSE 0 END)) AS "19",
SUM ( (CASE WHEN Hour = '19'and MIN > '31' THEN 1 ELSE 0 END)) AS "19.5",
SUM ( (CASE WHEN Hour = '20'and MIN < '30' THEN 1 ELSE 0 END)) AS "20",
SUM ( (CASE WHEN Hour = '20'and MIN > '31' THEN 1 ELSE 0 END)) AS "20.5",
SUM ( (CASE WHEN Hour = '21'and MIN < '30' THEN 1 ELSE 0 END)) AS "21",
SUM ( (CASE WHEN Hour = '21'and MIN > '31' THEN 1 ELSE 0 END)) AS "21.5",
SUM ( (CASE WHEN Hour = '22'and MIN < '30' THEN 1 ELSE 0 END)) AS "22",
SUM ( (CASE WHEN Hour = '22'and MIN > '31' THEN 1 ELSE 0 END)) AS "22.5",
SUM ( (CASE WHEN Hour = '23'and MIN < '30' THEN 1 ELSE 0 END)) AS "23",
SUM ( (CASE WHEN Hour = '23'and MIN > '31' THEN 1 ELSE 0 END)) AS "23.5",
SUM ( (CASE WHEN Hour = '00'and MIN < '30' THEN 1 ELSE 0 END)) AS "00",
SUM ( (CASE WHEN Hour = '00'and MIN > '31' THEN 1 ELSE 0 END)) AS "00.5",
SUM ( (CASE WHEN Hour = '01'and MIN < '30' THEN 1 ELSE 0 END)) AS "01",
SUM ( (CASE WHEN Hour = '01'and MIN > '31' THEN 1 ELSE 0 END)) AS "01.5",
SUM ( (CASE WHEN Hour = '02'and MIN < '30' THEN 1 ELSE 0 END)) AS "02",
SUM ( (CASE WHEN Hour = '02'and MIN > '31' THEN 1 ELSE 0 END)) AS "02.5",
SUM ( (CASE WHEN Hour = '03'and MIN < '30' THEN 1 ELSE 0 END)) AS "03",
SUM ( (CASE WHEN Hour = '03'and MIN > '31' THEN 1 ELSE 0 END)) AS "03.5",
SUM ( (CASE WHEN Hour = '04'and MIN < '30' THEN 1 ELSE 0 END)) AS "04",
SUM ( (CASE WHEN Hour = '04'and MIN > '31' THEN 1 ELSE 0 END)) AS "04.5",
SUM ( (CASE WHEN Hour = '05'and MIN < '30' THEN 1 ELSE 0 END)) AS "05",
SUM ( (CASE WHEN Hour = '05'and MIN > '31' THEN 1 ELSE 0 END)) AS "05.5",
SUM ( (CASE WHEN Hour = '06'and MIN < '30' THEN 1 ELSE 0 END)) AS "06",
SUM ( (CASE WHEN Hour = '06'and MIN > '31' THEN 1 ELSE 0 END)) AS "06.5",
SUM ( (CASE WHEN Hour = '07'and MIN < '30' THEN 1 ELSE 0 END)) AS "07",
SUM ( (CASE WHEN Hour = '07'and MIN > '31' THEN 1 ELSE 0 END)) AS "07.5",
SUM ( (CASE WHEN Hour = '08'and MIN < '30' THEN 1 ELSE 0 END)) AS "08",
SUM ( (CASE WHEN Hour = '08'and MIN > '31' THEN 1 ELSE 0 END)) AS "08.5",
SUM ( (CASE WHEN Hour = '09'and MIN < '30' THEN 1 ELSE 0 END)) AS "09",
SUM ( (CASE WHEN Hour = '09'and MIN > '31' THEN 1 ELSE 0 END)) AS "09.5",
SUM ( (CASE WHEN Hour = '10'and MIN < '30' THEN 1 ELSE 0 END)) AS "10",
SUM ( (CASE WHEN Hour = '10'and MIN > '31' THEN 1 ELSE 0 END)) AS "10.5",
SUM ( (CASE WHEN Hour = '11'and MIN < '30' THEN 1 ELSE 0 END)) AS "11",
SUM ( (CASE WHEN Hour = '11'and MIN > '31' THEN 1 ELSE 0 END)) AS "11.5",
SUM ( (CASE WHEN Hour = '12'and MIN < '30' THEN 1 ELSE 0 END)) AS "12",
SUM ( (CASE WHEN Hour = '12'and MIN > '31' THEN 1 ELSE 0 END)) AS "12.5",
SUM ( (CASE WHEN Hour = '13'and MIN < '30' THEN 1 ELSE 0 END)) AS "13",
SUM ( (CASE WHEN Hour = '13'and MIN > '31' THEN 1 ELSE 0 END)) AS "13.5",
SUM ( (CASE WHEN Hour = '14'and MIN < '30' THEN 1 ELSE 0 END)) AS "14",
SUM ( (CASE WHEN Hour = '14'and MIN > '31' THEN 1 ELSE 0 END)) AS "14.5",
SUM ( (CASE WHEN Hour = '15'and MIN < '30' THEN 1 ELSE 0 END)) AS "15",
SUM ( (CASE WHEN Hour = '15'and MIN > '31' THEN 1 ELSE 0 END)) AS "15.5",
SUM ( (CASE WHEN Hour = '16'and MIN < '30' THEN 1 ELSE 0 END)) AS "16",
SUM ( (CASE WHEN Hour = '16'and MIN > '31' THEN 1 ELSE 0 END)) AS "16.5",
SUM ( (CASE WHEN Hour = '17'and MIN < '30' THEN 1 ELSE 0 END)) AS "17",
SUM ( (CASE WHEN Hour = '17'and MIN > '31' THEN 1 ELSE 0 END)) AS "17.5"
FROM
( SELECT CASE
WHEN TO_CHAR (End_Tran_Time, 'HH24') BETWEEN '00' AND '05'
THEN
TRUNC (End_Tran_Time - 1)
ELSE
TRUNC (End_Tran_Time)
END
AS End_Tran_Time,
TO_CHAR (End_Tran_Time, 'HH24') AS Hour,
TO_CHAR(End_Tran_Time,'MI') As Min,
Order_number
FROM Table_1
Where Order_number Like '%1234%'
)
GROUP BY End_Tran_Time
order by order_date desc nulls last;