I have the following mysql statement basically doing what I want it to do except for one thing.
SELECT
a.tmc, w.date, ROUND(AVG(a.surface_temperature), 0) surface_temperature, ROUND(AVG(a.air_temperature), 0) air_temperature,
ROUND(AVG(a.material_rate),0) material_rate,
Time_Format(w.time, '%H:00') as time,
ROUND(AVG(w.intensity), 0) intensity,
FROM application a
LEFT OUTER JOIN weather w ON a.DATE = w.DATE AND a.tmc = w.tmc
WHERE w.DATE = '" & calendar1.SelectedDate & "'
AND w.event= '" & weatherType.SelectedItem.Value & "'
AND w.City = '" & sender.CssClass & "'
GROUP BY time
This Produces:
This is fine开发者_运维百科 but the problem is there are multiple TMCs per location (Think of TMC's as fire stations in city. Big Cities have multiple TMCs
What I need it to do is average everything like it does per hour but do it for every tmc, not just the first tmc that comes up based off the time and other filtered criteria.
I attmped both:
GROUP BY TIME AND TMC
and
GROUP BY TMC
but they both provide only 1 time and the 1 location.
How do I need to tweak this statement so it pulls the average of all this criteria per hour per tmc?
I want something with the following output:
Time TMC Temp
4:00 107+4807 27
4:00 108+3352 32
5:00 107+4807 28
5:00 105+2274 28
I hop this makes sense
I think you need to comma-separate them:
GROUP BY time, tmc
It's perhaps not that clear in the manual page for the SELECT
statement:
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
i.e., you can specify multiple columns to form more granular groups.
When you specify a logical combination like
GROUP BY TIME AND TMC
things might appear to work, but the groups produced will depend on the 'logical' value of time and tmc - you'll get a group for the rows where both appear 'true' and a group for everything else.
Yeah, comma separate the group by values. The first one will take priorty. So if you said GROUP BY TIME, TMC
it would group by TIME
and where TIME
is the same it will then group by TMC
精彩评论