postgresql - postgres min/max group by day of week from date range -
hi have tables has one-to-one relation
report_sites
id | date 1 | 2016-11-02 10:00:00 2 | 2016-11-02 11:00:00 3 | 2016-11-02 12:00:00 4 | 2016-11-03 17:00:00 5 | 2016-11-03 16:00:00
report_services
id | min_serving_time | max_serving_time | report_site_id 1 | 00:00:30.094 | 00:15:30.662 | 1 2 | 00:00:07.566 | 00:07:49.72 | 2 3 | 00:00:07.787 | 00:26:27.587 | 3
i want select min(min_serving_time) max(max_serving_time) date range group weekday this
weekday | min | max sunday | 00:00:05 | 00:08:55 monday | 00:01:51 | 00:05:21 tuesday | |
i can count rows of weekdays how aggregate value
select count(extract(dow report_sites.date) = 1 or null) monday, count(extract(dow report_sites.date) = 2 or null) tuesday, count(extract(dow report_sites.date) = 3 or null) wednesday, count(extract(dow report_sites.date) = 4 or null) thursday, count(extract(dow report_sites.date) = 5 or null) friday report_sites inner join "report_services" on "report_sites"."id" = "report_services"."report_site_id" report_sites.date >='2016-11-02' , report_sites.date<='2016-11-07'
thank , suggestions.
Comments
Post a Comment