i have 2 table (device_a & device_b), i want to :
- union the table to and count the data for each table then group by date hour.
- after that i want to count data for all device then group by date hour. there is no key for join table.
- the result show the id based on order by date hour
device_a
datetime
2020-09-23 16:00:00
2020-09-23 16:00:00
2020-09-23 16:00:00
2020-09-23 17:00:00
device_b
datetime
2020-09-23 16:00:00
2020-09-23 16:00:00
2020-09-23 17:00:00
2020-09-23 17:00:00
expected result:
id datehour type count
1 2020-09-23 16:00:00 device_a 3
2 2020-09-23 16:00:00 device_b 2
3 2020-09-23 16:00:00 device_all 5
4 2020-09-23 17:00:00 device_a 1
5 2020-09-23 17:00:00 device_b 2
6 2020-09-23 17:00:00 device_all 3