不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
巧用having解决统计问题
编辑:dnawo 日期:2011-12-08
有一张学员考试分数表结构如下:
给表中添加一些测试数据:
①.统计已经参加过科目一、科目二和科目三考试的学员:
引用内容
②.统计过了三个科目的学员:
引用内容
复制内容到剪贴板
程序代码

create table ScoreTB
(
Id int identity(1,1) primary key,
UserId int, --学员编号
Course int, --科目
Score int --分数
)
(
Id int identity(1,1) primary key,
UserId int, --学员编号
Course int, --科目
Score int --分数
)
给表中添加一些测试数据:
复制内容到剪贴板
程序代码

insert into ScoreTB(UserId,Course,Score) select 1,1,80
union all select 2,1,90
union all select 2,2,80
union all select 2,3,50
union all select 3,1,100
union all select 3,2,95
union all select 3,3,89
union all select 2,1,90
union all select 2,2,80
union all select 2,3,50
union all select 3,1,100
union all select 3,2,95
union all select 3,3,89
①.统计已经参加过科目一、科目二和科目三考试的学员:
复制内容到剪贴板
程序代码

select UserId from ScoreTB where Course in (1,2,3) group by UserId having count(*)=3

UserId
-----------
2
3
(所影响的行数为 2 行)
-----------
2
3
(所影响的行数为 2 行)
②.统计过了三个科目的学员:
复制内容到剪贴板
程序代码

select UserId from ScoreTB where Course in (1,2,3) and Score>=60 group by UserId having count(*)=3

UserId
-----------
3
(所影响的行数为 1 行)
-----------
3
(所影响的行数为 1 行)






评论: 0 | 引用: 0 | 查看次数: 3382
发表评论
请登录后再发表评论!