mysql 高手帮忙看下 很急

[复制链接]
查看11 | 回复3 | 2010-10-13 16:01:26 | 显示全部楼层 |阅读模式
我有两张关联表 A表的Oid 是B表的id
A表B表
A表字段有 B表字段有
id
Oid
state
id
name
1
1
未处理
1
张三
2
2
已处理
2
李四
3
2
未处理
3
王无
4
3
已处理
4
小强
我要得到的结果是:
姓名 出现次数 已处理次数
张三
1
0
李四
2
1
王五
1
1
请问我该怎么查 sql语句是怎样的啊(只能一条sql语句的)

回复

使用道具 举报

千问 | 2010-10-13 16:01:26 | 显示全部楼层
select b.name,count(*),ifnull(sum(case when a.state='已处理' then 1 else 0 end),0) from a,b where a.oid=b.idgroup by b.name
回复

使用道具 举报

千问 | 2010-10-13 16:01:26 | 显示全部楼层
select B.name,count(1) num,sum(case when A.state='已处理' then 1 else 0 end) as edit from A,B where A.Oid=B.id group by B.name;
回复

使用道具 举报

千问 | 2010-10-13 16:01:26 | 显示全部楼层
select c.name,c.N,d.m from (select b.id,b.name,count(*) N from a ,b where a.oid=b.id) C,(select b.id,count(*) M from a ,b where a.oid=b.id and a.state='已处理') Dwhere c.id=
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行