当前位置: 代码迷 >> Sql Server >> 求一条联合查询的sql解决方法
  详细解决方案

求一条联合查询的sql解决方法

热度:75   发布时间:2016-04-27 18:05:33.0
求一条联合查询的sql
以学生选课系统为例,有三个表 
student,包括sid,sname;
course, 有cid,cname,关键是有一个是否停课的字段,假设为tingke
然后有一个关系表 selectcourse,字段是sid,cid以实现student和course的多对多连接

希望查询学生的课程里面没有停课的课程数目。大致结果应该这样
sid1 sname1 4
sid2 sname2 2
......

谢谢!

------解决方案--------------------
SQL code
select  a.sid,a.sname,  sum(case tingke when '没有停课' then 1 else 0 end) as 没有停课from  student a,course b,selectcourse cwhere  a.sid=c.sidand  b.cid=c.cidgroup by  a.sid,a.sname
  相关解决方案