如何统计一个表中的多个字段相同值的记录数?
ACCESS数据库中有如下表(aid、bid、cid)分别代表在a、b、c三个环节中所做工作的工人ID号:aidbidcid12123222123现想统计每个工人在每个环...
ACCESS数据库中有如下表(aid、bid、cid)分别代表在a、b、c三个环节中所做工作的工人ID号:
aid bid cid
1 2 1
2 3
2 2 2
1 2 3
现想统计每个工人在每个环节中的记录数,即生成如下表:
ID A B C
1 2 1
2 2 3 1
3 1 1
第一个表中的aid bid cid均对应着第二个表中的ID 展开
aid bid cid
1 2 1
2 3
2 2 2
1 2 3
现想统计每个工人在每个环节中的记录数,即生成如下表:
ID A B C
1 2 1
2 2 3 1
3 1 1
第一个表中的aid bid cid均对应着第二个表中的ID 展开
1个回答
展开全部
留个标记
-------------------------补充,总算解决了这儿问题,方法可能不是很好-------------------
[TEST1@orcl#23-3月 -10] SQL>select * from t5;
AID BID CID
---------- ---------- ----------
1 2 1
2 3
2 2 2
1 2 3
[TEST1@orcl#23-3月 -10] SQL>select c.cid,a.total,b.total,c.total from (
2 select cid,count(cid) as total from t5 where cid is not null group by cid) c
3 left join (select aid,count(aid) as total from t5 group by aid) a on c.cid=a.aid
4 left join (select bid,count(bid) as total from t5 group by bid) b on c.cid=b.bid
5 order by c.cid;
CID TOTAL TOTAL TOTAL
---------- ---------- ---------- ----------
1 2 1
2 2 3 1
3 1 1
-------------------------补充,总算解决了这儿问题,方法可能不是很好-------------------
[TEST1@orcl#23-3月 -10] SQL>select * from t5;
AID BID CID
---------- ---------- ----------
1 2 1
2 3
2 2 2
1 2 3
[TEST1@orcl#23-3月 -10] SQL>select c.cid,a.total,b.total,c.total from (
2 select cid,count(cid) as total from t5 where cid is not null group by cid) c
3 left join (select aid,count(aid) as total from t5 group by aid) a on c.cid=a.aid
4 left join (select bid,count(bid) as total from t5 group by bid) b on c.cid=b.bid
5 order by c.cid;
CID TOTAL TOTAL TOTAL
---------- ---------- ---------- ----------
1 2 1
2 2 3 1
3 1 1
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询