I have a table with fallowing columns:
id device_id (string) used_at (datetime) app_id (string) duration (int)
1 device-1 2018-07-20 chrome 30
2 device-1 2018-07-19 chrome 1
3 device-2 2018-07-19 chrome 2
4 device-2 2018-07-20 facebook 100
5 device-1 2018-07-20 chrome 20
6 device-3 2018-07-20 chrome 10
7 device-1 2018-07-20 facebook 5
I need to get list of ten most used app_id for specified device-1 and used_at this list should have duration sum
So I should get for device-1 and uset_at >= 2018-07-18:
device-1 chrome duration (51)
device-1 facebook duration (5)
Anyone can suggest sql ?
Best Answer
I am not exactly sure what you are asking for in this post.
Here is what I came up with
Could you explain your question a little more so the rest of us can understand what you are trying to accomplish here?
If you want the top 2 of any and all devices then use this: