MySQL count problem
I have a table course:
CREATE TABLE course
(COURSE_NO NUMERIC(8,0) NOT NULL
,DESCRIPTION VARCHAR(50)
,COST NUMERIC(9,2)
,PREREQUISITE NUMERIC(8,0)
,CREATED_BY VARCHAR(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR(30)
,MODIFIED_DATE DATE
,PRIMARY KEY (COURSE_NO)
开发者_如何学运维 ,INDEX (PREREQUISITE)
) TYPE = INNODB;
I want to retrieve prerequisites and display the number of courses it is a prerequisite of
So far i understand i have to count the number of prerequisites a course has, but i dont understand how to display a count for each prerequisite.
Any help with this select statement would be appreciated.
Thanks, Mike
Assuming my comment is correct, this should work:
SELECT COUNT(*), prerequisite FROM course GROUP BY prerequisite;
精彩评论