求这样一个Sql 语句:用一条语句求出不同条件下的行数;详见正文 ( 积分: 100 )

  • 主题发起人 永不言悔
  • 开始时间

永不言悔

Unregistered / Unconfirmed
GUEST, unregistred user!
问题一:
一个表中某个字段(学号)有不同的值,怎样用一条sql语句求出不同学号的记录数,并且赋予标识。
问题二:
怎样使where 后面的条件与前面选择的字段一一对应。
 
Y

ysai

Unregistered / Unconfirmed
GUEST, unregistred user!
select sum(case 字段 when 值1 then
1 else
0 end), --字段值 = 值1 的记录数
sum(case 字段 when 值2 then
1 else
0 end) --字段值 = 值2 的记录数
from 表
 
W

weichao9999

Unregistered / Unconfirmed
GUEST, unregistred user!
问题一:
select 学号,count(*) as 记录数 from table group by 学号
问题二: 不明白
 

永不言悔

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 

Similar threads

S
回复
0
查看
948
SUNSTONE的Delphi笔记
S
S
回复
0
查看
769
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
398
import
I
顶部