我使用的是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)