Click to See Complete Forum and Search --> : Simple count query


seafordcrownfc
12-07-2007, 09:20 AM
Hi all,

I have a table called 'wld' in my 'sfcmtch' table where the value will either be w, d or l.

I want to be able to count the number of w's, d's and l's.

How is the best way of doing this ?

I will be putting this into a ASP.Net page but am struggling with the initial bit, which is the SQL.

Thanks.

WolfShade
12-07-2007, 11:37 AM
Not tested, but I think it's

SELECT count(column_name) FROM table_name WHERE column_name='w'
SELECT count(column_name) FROM table_name WHERE column_name='d'
SELECT count(column_name) FROM table_name WHERE column_name='l'

I rarely use count in SQL, but I think this will work.

^_^

seafordcrownfc
12-08-2007, 05:37 AM
I'm doing it in an ASP.Net page, would you recommend doing it another way then ?

mattyblah
12-11-2007, 12:12 AM
SELECT Sum(case when column_name = 'w' then 1 else 0 end) as w_count, Sum(case when column_name = 'd' then 1 else 0 end) as d_count, Sum(case when column_name = 'l' then 1 else 0 end) as l_count
FROM table_name