SELECT distinct
REPLACE(CM_NAME, \'/\', \' \') as CM_NAME,
TO_CHAR(Booking_Date,\'MM/DD/YYYY\') AS Booking_Date where Booking_Date =
\'03/20/2018\',
sum(
The code you posted doesn't have a from
clause, but you said you just hadn't included it. It does, however, have a where
clause - which is in the wrong place. It is also comparing a date with a string, which isn't a good idea as it relies on implicit conversion and session NLS settings. (Perhaps you think it can compare the fixed string with the date you just converted to a string - but that isn't the case, at least in the same level of query, and would be inefficient anyway in this case.) And as you are using aggregate function you need a group-by clause...
It would seem like you want:
SELECT REPLACE(CM_NAME, '/', ' ') as CM_NAME,
TO_CHAR(Booking_Date,'MM/DD/YYYY') AS Booking_Date,
sum(Air_Revenue) as TTL_AIRFARE,
sum(Room_Revenue) as TTL_ROOM,
sum(Car_Revenue) AS TTL_CAR,
sum(Activity_Revenue) as TTL_ACTIVITY,
0 as TTL_CRUISE
FROM your_table
WHERE Booking_Date = DATE '2018-03-20'
GROUP BY REPLACE(CM_NAME, '/', ' '),
Booking_Date
or if you want yesterday's date without having to specify it you can use:
WHERE Booking_Date = TRUNC(sysdate - 1)
GROUP BY REPLACE(CM_NAME, '/', ' '),
Booking_Date
That will only match rows where the Booking_Date
is at exactly midnight. If it actually includes other times then you can do:
WHERE Booking_Date >= TRUNC(sysdate - 1)
AND Booking_Date < TRUNC(sysdate)
GROUP BY REPLACE(CM_NAME, '/', ' '),
TO_CHAR(Booking_Date,'MM/DD/YYYY')
which will include a single full day of data.