Gerald Gerald - 1 month ago 16
PHP Question

SQL server 2000, return number of cells with the same values

1
1
1
2
2
2
2
3


For example I have the following data in a table, now I want to count rows with the same values so that I will have:

1 = 3 (cells with the value of 1 returns a count of 3)
2 = 4 (...)
3 = 1 (...)


I want to get results like this because I want to create a dynamic rowspan on an html table... Any help would be appreciated.. by the way I am using php and mssql server 2000..

Answer
 select count(*) from table where field=value;

Edit:

SELECT SUM(CASE WHEN gender = 'm' THEN 1 ELSE 0 END) m
 , SUM(CASE WHEN gender = 'f' THEN 1 ELSE 0 END) f
 FROM members;

This thread might help:

http://forums.mysql.com/read.php?20,397163,397178

Comments