0

我是一个非常基础的用户,所以请放轻松。这是我的问题,我正在尝试计算同一列的数量,但使用不同的子句。我想将来自同一个数据库/表的 2 个查询合并为一个。我确定这很简单...

1

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

2

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

任何帮助,将不胜感激。

4

1 回答 1

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

您也可以将另一个 GROUP by item 添加到 it_source 字段上的原始查询之一。

于 2013-05-07T15:56:35.430 回答