标题:sql合并
只看楼主
cy1210
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-4-26
结帖率:0
已结贴  问题点数:20 回复次数:1 
sql合并
如何将下列两个sql 合成一个简单的sql???

SELECT DPItemId,COUNT(1) idcount
FROM  T
where     DPDate<='2016-04-15'
group by DPItemId
having count(1) <=10
 ) as t


select count(*)  from (SELECT DPItemId,COUNT(1) idcount
FROM T2
where  DPDate<='2016-04-15'
group by DPItemId
having count(1) >10   
and count(1) <=50
) as t

搜索更多相关主题的帖子: 如何 
2016-04-26 21:03
dairui
Rank: 2
等 级:论坛游民
帖 子:4
专家分:30
注 册:2007-7-22
得分:20 
SELECT DPItemId,sum(idcount) idcount,sum(idcount2) idcount2
from (
SELECT DPItemId,COUNT(1) idcount,0 idcount2
FROM  T
where     DPDate<='2016-04-15'
group by DPItemId
having count(1) <=10
union all
SELECT DPItemId,0 idcount,COUNT(1) idcount2
FROM T2
where  DPDate<='2016-04-15'
group by DPItemId
having count(1) >10   
and count(1) <=50
) a
group by DPItemId
2016-05-01 23:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464152-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087603 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved