sql 查询语句合并有关问题
sql 查询语句合并问题
我想请问各位
select pStreet,count(distinct pComname) comnameNum
from tbl_Product
where pStreet in (select distinct pStreet from tbl_Product)
group by pStreet 单位和行业数量
select distinct pComname ,count(cTime) cTimeNum from tbl_Condition where cTime is not null
group by pComname 巡检数量
select COUNT(distinct pComname) from tbl_Condition 巡检间数
如何把上面这3条查询语句合并成一条查询语句?很急啊~~高分送上
------解决方案--------------------
try this,
------解决方案--------------------
我想请问各位
select pStreet,count(distinct pComname) comnameNum
from tbl_Product
where pStreet in (select distinct pStreet from tbl_Product)
group by pStreet 单位和行业数量
select distinct pComname ,count(cTime) cTimeNum from tbl_Condition where cTime is not null
group by pComname 巡检数量
select COUNT(distinct pComname) from tbl_Condition 巡检间数
如何把上面这3条查询语句合并成一条查询语句?很急啊~~高分送上
SQL
select
合并
------解决方案--------------------
try this,
select * from
(
select pStreet,count(distinct pComname) comnameNum
from tbl_Product
where pStreet in (select distinct pStreet from tbl_Product)
group by pStreet
union all
select distinct pComname,count(cTime) cTimeNum
from tbl_Condition
where cTime is not null
group by pComname
union all
select '',COUNT(distinct pComname)
from tbl_Condition
) t
------解决方案--------------------
SELECT MAX(pStreet) pStreet ,
SUM(comnameNum) comnameNum ,
MAX(pComname) pComname ,
SUM(cTimeNum) cTimeNum ,
SUM(pComname) pComname
FROM ( SELECT pStreet ,
COUNT(DISTINCT pComname) comnameNum ,
NULL AS pComname ,
0 AS cTimeNum ,
0 AS pComname
FROM tbl_Product
WHERE pStreet IN ( SELECT DISTINCT
pStreet
FROM tbl_Product )