sql - How to compute monthly interval average and group by month -
I am using postgres.
I have the following questions, which calculates an average time interval is correct every day of the month, at least every day where I have the data available:
SELECT date_part ('year': text, c.date) AS yyyy, to_char (c.date, 'MM' :: text) as monthnumber, TO_CHAR (C. Date, 'TMMonth' :: text) MONTHNAME , In the form of l.name lineName, the average (COALESCE (c.observed_arrival_time, v.arrival_time) - v.arrival_time) as time_difference in counter c on v.id = c.vj_at_stop_id vehicule_journey_at_stop v Join vehicule_journey vv Join vv.id = v.vehicu Join le_journey_id at route_analyse r.id = vv.route_id Join line L but join l.id = r.line_id pt_network at n.id = l.network_id Where date_part ('year', c. Daat) = 2014 and by c.name = 'montée' 1,2,3,4,5 Order 1,2 by Group Most of what I want, the results look like this: / P>
... 2014; "07"; "Julet"; "2014-07-12"; "Ligne 01", "00: 04: 16.0685" 2014, "07", "Juillet", "2014-07-20", "ligne 01", "00: 04: 56.5,0 9, 875" 2014, "07", "Juillet"; "2014-07-23"; "Ligne 02"; "00:00:00" 2014; "07"; "Julet"; "2014-07-24"; "Lign 03"; "00:00:00" ... The important thing is that the average time in the last position, the calculation for each "line" (eg "ligne 01" or ligne "02 ").
The thing is, I want to group those results by month, in which average intervals are available for months of each month, i.e .::
. 2014, "07", "Juillet", "Ligne 01", "00: 04: 36.5 9, 74,375" 2014, "07", "Juillet", "Ligne 02", "0:00: 00 "2014;" 07 ";" Julette ";" Ligne 03 ";" 00:00:00 "... But I can not get it to work. If I remove c.date from the selection (due to which my data is not classified by month, but by the day, I think that), I get false average prices I
rewrite "group" using real numbers, not just numbers, and Remove c.date, then select it is easy.
Comments
Post a Comment