首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

各位大侠:按照A表的某一键值统计在C表出现的总数

2012-08-03 
求助各位大侠:按照A表的某一键值统计在C表出现的总数有A,B,C三张表中,A.snB.index, B.ipC.ip按照A表的sn

求助各位大侠:按照A表的某一键值统计在C表出现的总数
有A,B,C三张表中,A.sn=B.index, B.ip=C.ip
按照A表的sn,分别统计在C表中的总数。

[解决办法]

SQL code
select  a.sn,count(c.ip)from  a,b,cwhere  A.sn=B.index and B.ip=C.ipgroup by  a.sn
[解决办法]
SQL code
select a.sn,c.cntfrom ajoin b on A.sn=B.[index]join (select ip,count(1) as cnt from c group by ip) c on b.ip=c.ipgroup by a.sn,c.cnt
[解决办法]
SQL code
select  a.sn,count(c.ip)from  a,b,cwhere  A.sn=B.index and B.ip=C.ipgroup by  a.sn
[解决办法]
SQL code
select  a.sn,count(c.ip)from ainner join b on A.sn=B.index inner join c on B.ip=C.ipgroup by a.sn 

热点排行