Skip to content
Advertisement

want to use sql count online people with begintime and endtime

I want to use sql count online people with begintime and endtime on presto。

my data like :

I want to Count people online every hour. Now I have a stupid way to count. My sql like :

Is there an easier way to do this? THX

Advertisement

Answer

In Prestodb, you can generate an array with integer values and then unnest them to get the hours. Then use joins and group by to do the calculations you want:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement