作者nosezhao (赏月亮一巴掌)
看板Database
标题Re: [SQL ] mysql语法请教
时间Tue May 15 22:20:56 2007
※ 引述《kevin524 (等待的天空)》之铭言:
: 请问一下
: 假如我有一个table
: 要依据栏位进行不同值的的count计算
: 最後依据计算出来的key值做合并
: 要如何做到?谢谢!!
: 如table有4个栏位
: 时间 | 节次 | 参与上课 | 学号
: 2007-5-15 2 1 abc
: 2007-5-15 2 0 cde
: 2007-5-15 3 1 dfg
: 2007-5-15 3 1 ekj
: 2007-5-16 3 0 kfj
: 2007-5-16 3 0 qwe
: 时间 | 节次 | 上课人数 | 缺席人数
: 2007-5-15 2 2 1
: 2007-5-15 3 3 0
: 2007-5-16 3 2 2
: 以上结果要怎麽下语法才能做到,谢谢!!
没有经过验证,或许有细部需要调整
select distinct x.时间 , x.节次 ,
(select count(*) from table
where 时间=x.时间 and 节次=x.节次 and 参与上课=1) as 上课人数 ,
(select count(*) from table
where 时间=x.时间 and 节次=x.节次 and 参与上课=0) as 缺席人数
from table x
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.160.26.75