简单问题,3表关联,50分
有3表
表a
表b
表c
通过表a知道表b的值,通过表b知道表c的值
a
number
serv_id
b
serv_id
exch_id
nwk_id
c
nwk_id
describ
输入number-> 通过a得到serv_id-> 通过serv_id查表b-> 得到nwk_id-> nwk_id在C表中不止一条
我想得到的结果是
a.number,b.exch,c中的此number对应的nwk_id的条数
比如单条数据
1234567(number)-> 321(serv_id),334(exch_id)-> 678(nwk_id)
然后我count下C表中nwk_id等于678的条数是2
结果是
1234567,334,2
现在我有100多万数据....求助.谢谢
------解决方案--------------------select a.number,b.exch_id,count(*)
from a inner join b
on a.serv_id=b.serv_id
inner join c
on b.nwk_id=c.nwk_id
group by a.number,b.exch_id
--这样行不
------解决方案--------------------select a.number,b.exch_id,count(*)
from a ,b, c
where a.serv_id=b.serv_id
and b.nwk_id=c.nwk_id
group by a.number,b.exch_id
------解决方案--------------------select a.number ,
b.exch_id,
count(1)
from a ,
inner join b
inner join c on
a.serv_id = b.serv_id
and b.nwk_id = c.nwk_id
group by a.number ,
b.exch_id
------解决方案--------------------advancejar(金谜) 你听我说,正确解决方法如下:
======================================================================
你的表结构为:
a(number , serv_id)
b( serv_id, exch_id, nwk_id)
c( nwk_id, describ)
======================================================================
操作语句为:
select a.numbers,b.exch_id,count(*)
from a ,b , c
where a.serv_id=b.serv_id
and b.nwk_id=c.nwk_id
group by a.numbers,b.exch_id
======================================================================