2013-05-07 67 views
0

我是一個非常基本的用戶,所以對我來說很容易。這是我的問題,我試圖得到同一列的計數,但是使用了不同的子句。我想從同一個數據庫/表中的2個查詢合併成一個。我敢肯定,這很簡單...同一個數據庫,同一個表,相同的查詢,但不同的地方從句

Select count(inquiry_id) as 'Emails Tickets' 
    , owner_rep 
From sv_inquiry 
Where logged_dt > '5/6/2013 0:00:00' 
    and owner_grp in ('it service desk','corporate support') 
    and it_source = 'email' 
group by owner_rep 
Select count(inquiry_id) as 'Tele Tickets' 
    , owner_rep 
From sv_inquiry 
Where logged_dt > '5/6/2013 0:00:00' 
    and owner_grp in ('it service desk','corporate support') 
    and it_source = 'telephone' 
Group by owner_rep 

任何幫助,將不勝感激。

回答

0

這是一種應該有效的方法。

Select sum(case when it_source='email' THEN 1 ELSE 0 END) emailTicketCount, 
     sum(case when it_source='Telephone' THEN 1 ELSE 0 END) TelephoneTicketCount, 
     owner_rep 
From sv_inquiry 
Where logged_dt > '5/6/2013 0:00:00' and owner_grp in ('it service desk','corporate support') 
group by owner_rep 

您也可以在it_source字段中爲其中一個原始查詢添加另一個GROUP by項。

相關問題