How to list the number of automobile crashes associated with each weather type in the descending order?

Go To StackoverFlow.com

0

I have a database with 12,000 records with various attributes. One of them is weather_condition (Integer).

This query will return every single car accident with weather type in descending order.

SELECT weather_condition FROM nyccrash ORDER BY weather_condition DESC;

What I want specifically is to display the count of how many accidents associated with each weather_condition. There are 7 conditions: 0 through 7.

For example:

Condition | Count
0         | 452
1         | 558
2         | 1242
3         | 92
...       | ...
2012-04-05 01:59
by Sahat Yalkabov


3

How about this:

SELECT weather_condition, COUNT(weather_condition) AS Count 
FROM nyccrash
GROUP BY weather_condition
ORDER BY weather_condition DESC ;
2012-04-05 02:01
by Justin Pihony
Your Order By needs to be after your Group By. Other than that, this one should work fine - Michael Rice 2012-04-05 02:02
@MichaelRice Yah, I noticed that little faux pas and fixed it already. Thanks - Justin Pihony 2012-04-05 02:03
Great! That works, thanks - Sahat Yalkabov 2012-04-05 02:04
Ads