avatar

数据库题

数据库题目

sql语句

教师号  星期号 是否有课
 1    2   有
 1    3   有
 2    1   有
 3    2   有
 1    2   有
通过一条语句转换为
教师号 星期一 星期二 星期三
 1       2   1 
 2   1   
 3       1

1
2
3
4
select 教师号,sum(星期一)as 星期一,sum(星期二) as 星期二,sum(星期三)as 星期三 from (select id as "教师号",case when day=1 and up=1 then 1 else 0 end as 星期一,
case when day=2 and up=1 then 1 else 0 end as 星期二,
case when day=3 and up=1 then 1 else 0 end as 星期三
from teacher)A group by 教师号;

要使用流程控制语句

文章作者: fancylight
文章链接: https://www.fancylight.top/2019/05/10/%E6%95%B0%E6%8D%AE%E5%BA%93%E9%A2%98/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 博客
打赏
  • 微信
    微信
  • 支付寶
    支付寶

评论