Click to See Complete Forum and Search --> : counting columns


mizu_chil
February 6th, 2005, 12:48 PM
I have the following tables: student, section and status

Student Section Status
ben sec1 passed
ann sec1 passed
isaiah sec2 passed
mark sec2 failed


I would like to find a way or the sql statement to be able to produce this kind of result

Section No. of Failures
sec1 0
sec2 1

hope you can help me

j0nas
February 6th, 2005, 01:50 PM
Use the SQL COUNT function... Here is an example (using only one table Students, with fields: student, section and status):


SELECT section, COUNT(*) AS '# of failures'
FROM Students
WHERE status='passed'
GROUP BY section;

Krzemo
February 7th, 2005, 09:30 AM
Rather:

SELECT section, COUNT(*) AS '# of failures'
FROM Students
WHERE status='failed'
GROUP BY section;



Because output column name is '# of failures';)
:)

Best regards,
Krzemo.

j0nas
February 7th, 2005, 03:54 PM
Rather:

SELECT section, COUNT(*) AS '# of failures'
FROM Students
WHERE status='failed'
GROUP BY section;



Because output column name is '# of failures';)
:)

Best regards,
Krzemo.
Of course :blush: