34,588
社区成员
发帖
与我相关
我的任务
分享
select isnull([上午本地有效对话量],0)+isnull([下午本地有效对话量],0)+isnull([全天本地有效对话量],0) as 总本地有效对话量,
isnull([上午外地有效对话量],0)+isnull([下午外地有效对话量],0)+isnull([全天外地有效对话量],0) as 总外地有效对话量
from
(Select SUM(LocalValidCount) as 全天本地有效对话量,SUM(NoLocalValidCount) as 全天外地有效对话量 from DialogueQuantity where AllDayStatusDQ='True') as a,
(Select SUM(MorningLocalValidCount) as 上午本地有效对话量,SUM(MorningNoLocalValidCount) as 上午外地有效对话量 from DialogueQuantity where (AllDayStatusDQ is null and AfternoonStatusDQ is null and MorningStatusDQ='True')) as b,
(Select SUM(AfternoonLocalValidCount) as 下午本地有效对话量,SUM(AfternoonNoLocalValidCount) as 下午外地有效对话量 from DialogueQuantity where (AllDayStatusDQ is null and AfternoonStatusDQ = 'True')) as c
SELECT UID,ProjectID,sum([LocalValidCount]) as 总本地有效对话量,sum([NoLocalValidCount]) as 总外地有效对话量
FROM DialogueQuantity group by UID,ProjectID
select UID,ProjectID,
sum(case when AllDayStatusDQ='True' then LocalValidCount
when MorningStatusDQ='True' then MorningLocalValidCount
when AfternoonStatusDQ = 'True' then AfternoonLocalValidCount else 0 end) 总本地有效对话量,
sum(case when AllDayStatusDQ='True' then NoLocalValidCount
when MorningStatusDQ='True' then MorningNoLocalValidCount
when AfternoonStatusDQ = 'True' then AfternoonNoLocalValidCount else 0 end)总外地有效对话量
FROM DialogueQuantity
group by UID,ProjectID
select isnull([上午本地有效对话量],0)+isnull([下午本地有效对话量],0)+isnull([全天本地有效对话量],0) as 总本地有效对话量,
isnull([上午外地有效对话量],0)+isnull([下午外地有效对话量],0)+isnull([全天外地有效对话量],0) as 总外地有效对话量
from
(Select UID,ProjectID,SUM(LocalValidCount) as 全天本地有效对话量,SUM(NoLocalValidCount) as 全天外地有效对话量 from DialogueQuantity where AllDayStatusDQ='True' group by UID,ProjectID) as a,
(Select UID,ProjectID,SUM(MorningLocalValidCount) as 上午本地有效对话量,SUM(MorningNoLocalValidCount) as 上午外地有效对话量 from DialogueQuantity where (AllDayStatusDQ is null and AfternoonStatusDQ is null and MorningStatusDQ='True') group by UID,ProjectID) as b,
(Select UID,ProjectID,SUM(AfternoonLocalValidCount) as 下午本地有效对话量,SUM(AfternoonNoLocalValidCount) as 下午外地有效对话量 from DialogueQuantity where (AllDayStatusDQ is null and AfternoonStatusDQ = 'True') group by UID,ProjectID) as c
--sql2000
--1
select *
from (
-- 第一段SQL
) a join ( -- left join cross join etc...
-- 第二段SQL
) b on ....
--2
select ...
into #t1
from ...
where ...
select ...
into #t2
from ...
where ...
select *
from #t1 a join #t2 b on a.[] = b.[] -- left join cross join etc...
drop table #t1,#t2
;with ct1 as
(
--你的第一段SQL
),ct2 as
(
--你的第二段SQL
)
select *
from ct1 a join ct2 b on ... -- left join cross join etc...
--SQL2005及以上版本