日期:2014-05-18  浏览次数:20517 次

sql子查询,去重复!!!
select (select orgname from org as og where org.id=og.id),
(select count(*) from tb1 as t1 whree t1.id=org.id) as number1,
(select count(*) from tb2 as t2 whree t2.id=org.id) as number2,
(select count(*) from tb3 as t3 whree t3.id=org.id) as number3,
(select count(*) from tb4 as t4 whree t4.id=org.id) as number4,
(select count(*) from tb5 as t5 whree t5.id=org.id) as number5  
from org as org,tb as tb where org.id=tb.id 
group by org.name having count(*)>0

语句也就是这么个意思,现在是查出来了,可是有那么几行查询结果为0的也显示出来了,我不想显示全为0的这
一行记录
如下:
orgname ------number1-------number2-------number3-------number4------number5
aaaa-----------0--------------2--------------0-------------1------------0
bbbb-----------1--------------0--------------0-------------0------------0
cccc-----------0--------------0--------------0-------------0------------0
dddd-----------0--------------2--------------0-------------0------------0
eeee-----------0--------------1--------------0-------------1------------0

就是不取出number1,number2,number3,number4,number5全为0的这一行记录
求大师指明!!!!!



------解决方案--------------------
SQL code
--嵌套一下
where number1+number2+number3+number4+number5<>0

------解决方案--------------------
筛选一下,就只可以了:
SQL code
having number1+number2+number3+number4+number5<>0

------解决方案--------------------
探讨
SQL code
--嵌套一下
where number1+number2+number3+number4+number5<>0