查询学过“叶平”老师所教的所有课的同学的学号、姓名;
SELECT sc.S_id FROM course c , scores sc, teacher t
WHERE sc.C_id=c.id
AND t.id=c.T_id
AND t.Tname='叶平'
GROUP BY sc.S_id
HAVING COUNT (sc.C_id)
= (SELECT COUNT(c.id) FROM course c , teacher t
WHERE c.T_id=t.id
AND t.tname='叶平')
为什么报错:
FUNCTION study.count does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
求大神指导下。谢谢
我想先求出学生的id;
然后得到结果。
建表如下
CREATE TABLE Student
(
id INT(3) PRIMARY KEY NOT NULL AUTO_INCREMENT,
Sname VARCHAR(20) NOT NULL,
Sage INT(3) NOT NULL,
Ssex VARCHAR(10) NOT NULL
)
CREATE TABLE Course
(
id INT(3) PRIMARY KEY NOT NULL AUTO_INCREMENT,
Cname VARCHAR(20) NOT NULL,
T_id INT(3) NOT NULL
);
CREATE TABLE Scores
(
S_id INT(3) NOT NULL ,
C_id INT(3) NOT NULL,
score INT(3) NOT NULL
);
CREATE TABLE Teacher
(
id INT(3) PRIMARY KEY NOT NULL AUTO_INCREMENT,
Tname VARCHAR(20) NOT NULL
);
------解决方案--------------------LZ的代码是MySQL的语法吧?
try below.
select id,Sname
from Student
where id in
(select a.S_id
from Scores a
inner join Course b on a.C_id=b.id
inner join Teacher c on b.T_id=c.id
where c.Tname='叶平'
group by a.S_id
having count(1)=(select count(1)
from Course b2
inner join Teacher c2 on b2.T_id=c2.id
where c2.Tname='叶平'))
------解决方案--------------------http://blog.csdn.net/fredrickhu/article/details/4592668