Home > Software design >  PRESTO SQL count group by date
PRESTO SQL count group by date

Time:08-30

I have a Presto sql table called "imp_pixel".

Here a record of a table :

date_time                ip              impression_id
2022-08-27 07:05:48      192.0.0.1         001
2022-08-27 07:05:58      192.0.0.12        002

I would like to show the sum of impression_id group by hour

I tryed with this code

select
    date_trunc('hour', CAST(date_time AS date)) date_time,
    COUNT(impression_id,0) AS 'impression_id'
    from parquet_db.imp_pixel
    group by date_trunc('hour', date)

But I got this error :

line 3:31: mismatched input ''impression_id''. Expecting: <identifier>

Can you help me please to fix this error? thanks

CodePudding user response:

Formatting date_time to date, we lose the hourly data

select
date_trunc('hour', CAST(date_time AS timestamp)) date_time,
COUNT(impression_id) AS impression_id
from parquet_db.imp_pixel
group by 1
  • Related