sql查询语句

[复制链接]
查看11 | 回复2 | 2007-10-20 08:38:44 | 显示全部楼层 |阅读模式
现有表table1
id
uid isarrived
1
001
签到
2
002
签到
3
001
未到
4
001
签到
5
002
未到
我想得到如下结果
uid
uid出现次数
未到次数
001
3
1
002
2
1

请问以上输出结果。用sql如何实现
附:建立table1的sql如下:
create table table1
(
id varchar(100) not null,
uid varchar(100) null,
isarrived varchar(50) null
)
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
select uid,uid出现次数=count(*),未到次数=sum(case when isarrived = '未到' then 1 else 0 end)
from table1
group by uid
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
select A.uid,count(A.uid) as 'uid出现次数' ,
(selectcount(isarrived)-1 from table1 b
where isarrived='未到' group by isarrived ) AS '未到次数' from table1 A
group by A.uid
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行