【sql: 练习题19 ,20】查询每门课程被选修的学生数,查询出只选修两门课程的学生学号和姓名...

题目 19:查询每门课程被选修的学生数

SELECT courseid,COUNT(studentid) FROM student_score GROUP BY courseid;

运行:

 

练习题20 :查询出只选修两门课程的学生学号和姓名

SELECT student.*, r.a FROM student,
(SELECT studentid,COUNT(courseid) AS a FROM student_score GROUP BY student_score.studentid)r
WHERE r.a =2 AND student.id = r.studentid ;

运行:

 

转载于:https://www.cnblogs.com/yuanyuan2017/p/11365116.html

发布了0 篇原创文章 · 获赞 7 · 访问量 5万+
展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

mysql 插入数据中文乱码

04-08

我用navicat写的插入数据这样的话会失败,乱码。数据库和表的编码都是utf8的。后来我换了一种方法就成功了,就是改成了 insert into Student values('01' , '赵雷' , '1990-01-01' , '男'), ('02' , '钱电' , '1990-12-21' , '男'), ('03' , '孙风' , '1990-05-20' , '男'), ('04' , '李云' , '1990-08-06' , '男'), ('05' , '周梅' , '1991-12-01' , '女'), ('06' , '吴兰' , '1992-03-01' , '女'), ('07' , '郑竹' , '1989-07-01' , '女'), ('08' , '王菊' , '1990-01-20' , '女'); 以下是错误的以及提示,不懂为什么,版本的问题么 mysql> insert into Student values(04 , '李云' , '1990-08-06' , '男'); insert into Student values(05 , '周梅' , '1991-12-01' , '女'); insert into Student values(06 , '吴兰' , '1992-03-01' , '女'); insert into Student values('07' , '郑竹' , '1989-07-01' , '女'); insert into Student values('08' , '王菊' , '1990-01-20' , '女'); Query OK, 1 row affected 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 mysql> delete table student; 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table student' at line 1 mysql> drop table student; Query OK, 0 rows affected ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览