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--------------0--------------0-------------0------------0
eeee-----------0--------------1--------------0-------------1------------0
就是不取出number1,number2,number3,number4,number5全为0的这一行记录
求大师指明!!!!!
(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--------------0--------------0-------------0------------0
eeee-----------0--------------1--------------0-------------1------------0
就是不取出number1,number2,number3,number4,number5全为0的这一行记录
求大师指明!!!!!
...全文
相关推荐
数据库实验四:SQL数据查询.doc
数据库实验四:SQL数据查询.doc
在SQL Server中使用ISNULL执行空值判断查询
主要介绍了在SQL Server中使用ISNULL执行空值判断查询,ISNULL的好处是可以直接写在SELECT查询语句中,需要的朋友可以参考下
SQL 列不同的表查询结果合并操作
两个不同的表进行查询,需要把结果合并, 比如table1的列为 id, user_id, type_id,pro_id; table2的列为 id,user_id,collect_id;分别如下图所示 table1: table2: 将两个表的查询结果合并到一起的查询语句为 select *, null as collect_id from table1 where user_id = 527 union select id,user_id,null as type_id,null as pro_id, collect_id from table2 where user_id = 527
关于Orcale中not in与空值在查询上的问题
小白一名初次接触Oracle,在写到一道相关的查询的题时,被眼前一直查询不出的几个给折磨了一个多小时,特在此记录一下 题目是这个样子的=.=: 在Oracle 中查询在emp表中不是经理的员工的姓名! 然后,然后就要进入正题了…… 书写的语句很简单,也许也就是因为他比较简单吧,总是
将sql查询结果保存到数据表
sql查询,sql server,数据库导入导出,将查询结果插入表中


应用实例
