面试题目(sql)

2020-05-01 教育 78阅读
我使用的是MySQL 如下语句:
建表语句:
create table Lessoninfo(
no int,
week int,
isonduty char);
插入数据:略
insert into Lessoninfo values(...............)
SQL查询语句:
select no as '教师号', sum(week=1) as '星期一',sum(week=2) as '星期二',sum(week=3) as '星期三' from Lessoninfo group by no;
/***********************附结果******************
mysql> select no as '教师号', sum(week=1) as '星期一',sum(week=2) as '星期二',su
m(week=3) as '星期三' from Lessoninfo group by no;
+--------+--------+--------+--------+
| 教师号 | 星期一 | 星期二 | 星期三 |
+--------+--------+--------+--------+
| 1 | 0 | 2 | 1 |
| 2 | 1 | 0 | 0 |
| 3 | 0 | 1 | 0 |
+--------+--------+--------+--------+
3 rows in set (0.02 sec)
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com