SELECT * FROM user;
SELECT * FROM user WHERE id BETWEEN 2 AND 4;
SELECT * FROM user ORDER BY RAND() LIMIT 0,10;
SELECT user.name,yuan.yname FROM yuan,user WHERE user.yid=yuan.id HAVING yuan.yname='数学' OR yuan.yname='汉语文学';
SELECT * FROM user WHERE age BETWEEN 20 AND 25;
- 查出20到25岁的学生的成绩信息,要求显示学生名,课程名和分数
SELECT user.name, cores.cname,score.grade FROM user,cores,score WHERE
score.stu__id=user.id AND score.c_id=cores.id AND age BETWEEN 20 AND 25;
SELECT yuan.yname, COUNT(*) AS num FROM user,yuan WHERE user.yid=yuan.id GROUP BY yuan.yname;
SELECT * FROM user,score WHERE score.stu__id=user.id AND grade IS NULL;
SELECT user.name, sum(grade) FROM user,score WHERE score.stu__id=user.id GROUP BY user.name;
SELECT user.name, cores.cname,score.grade FROM cores,score,user
WHERE cores.id=score.c_id AND user.id=score.stu__id AND user.name='小五';
SELECT user.name, cores.cname,score.grade FROM cores,score,user
WHERE cores.id=score.c_id AND user.id=score.stu__id AND user.name LIKE '王%';
SELECT * FROM cores,user,score WHERE cores.id=score.c_id AND score.stu__id =user.id AND grade<95 AND cores.cname='计算机';
SELECT cores.cname,MAX(score.grade) FROM score,cores WHERE score.c_id=cores.id GROUP BY cores.cname;
SELECT user.id,user.name,user.sex,user.birth,user.age,user.address,cores.cname,score.grade FROM user,cores,score
WHERE user.id=score.stu__id AND cores.id=score.c_id;
SELECT user.name, sum(grade) FROM user,score WHERE score.stu__id=user.id GROUP BY user.name;
SELECT cores.cname,AVG(score.grade) FROM score,cores WHERE score.c_id=cores.id GROUP BY cores.cname;
SELECT * FROM student WHERE id IN
(SELECT
s.id
FROM student AS s,score AS sc,cores AS c
WHERE sc.stu__id = s.id AND sc.c_id = c.id AND c.cname = "英语" AND s.id IN
(SELECT
s.id
FROM student AS s,score AS sc,cores AS c
WHERE sc.stu__id = s.id AND sc.c_id = c.id AND c.cname = "计算机" ));
SELECT
*
FROM student AS s,score AS sc,cores AS c
WHERE sc.stu__id = s.id AND sc.c_id = c.id AND c.cname = "计算机" ORDER BY grade desc;
- 查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩
SELECT
s.name,2022-birth,y.yname,c.cname,grade
FROM student AS s,score AS sc,cores AS c,yuan AS y
WHERE sc.stu__id = s.id AND sc.c_id = c.id AND s.yid = y.id AND address LIKE "%湖南%";