Example data:
Name | Domain | Count | datetime
----------------------------------------------------
John | google | 5 | 2019-07-09 01:00:01
John | apple | 6 | 2019-07-09 01:02:01
John | apple | 8 | 2019-07-09 01:03:01
John | google | 10 | 2019-07-09 01:11:01
John | dos | 1 | 2019-07-09 01:11:01
John | dos | 3 | 2019-07-09 01:11:01
Expected output:
Name | max_Domain1| max_Count1 | max_Domain2 | max_Count2 | datetime
--------------------------------------------------------------------------
John | google | 10 | apple | 8 | 2019-07-09
I tried using row_number() over the partition, but it is giving me the same date values as top 2 maximum.
select t.*,
row_number() over (partition by name, date(datetime) order by count desc) as seqnum
from table t
where datetime >= '2019-07-08' and
datetime < '2019-07-09'
Try the following:
Example here
You seem to want the largest count per day:
You need to partition by only year,month and day not the whole datetime: