I have a query that I'm trying to aggregate data based on hours between two unix timestamps in Oracle. Hardest part is that I get error'd out with "ORA-00936: missing expression" error even I don't see anything wrong in the query. Need some expert advice here. Below is the query -
Query -
select DATE(FROM_UNIXTIME(C.DATETIMEORIGINATION)) the_date,
HOUR(FROM_UNIXTIME(C.DATETIMEORIGINATION)) the_hour,
count(c.RECORD_ID) the_count
FROM TABLE_A C
WHERE C.DATETIMEORIGINATION between 1380033019 AND 1379702408
GROUP BY 1,2;
Any help is greatly appreciated. Thanks
If you want the
the_date
field as an actual date:If you want the hour value as a number you can wrap that field in a
to_number()
call. If this is for display then you should explicitly format the date as well:Or with one field for the date and time together:
Depends what you want to see and what you're going to do with it.
Whichever fields you use for the aggregation, you need to specify them the same way in the
group by
clause - you can't use positional notation, e.g.group by 1, 2
. ANd you already realised that thebetween
values have to be in ascending order or it won't find anything at all.