2012-02-02 38 views
0

只是需要一些帮助/咨询与SQL Server 2005和Visual Studio 2005的SQL Server 2005和商业智能使用2个集一个报告

基本上我有2个数据集,其中一个导致良好的呼叫总数而另一个导致坏通话的数量。

我想做一个显示好坏率的报告。

,呼叫失败的actstatus有“105”

SELECT Country, count(status) AS FailedCalls 
FROM termactivity(nolock) 
INNER JOIN termconfig(NOLOCK) ON cfgterminalID = actterminalID 
WHERE actstatus IN (105) 
GROUP BY country 
ORDER BY country 

为了获得良好的通话actstatus在其细胞

SELECT Country, count(status) AS FailedCalls 
FROM termactivity(nolock) 
INNER JOIN termconfig(NOLOCK) ON cfgterminalID = actterminalID 
WHERE actstatus IN (5) 
GROUP BY country 
ORDER BY country 

有“5”现在这两种结果与国家名称和号码,如表低于

Country fails 
    AT 240 
    BE 3 
    CH 1 
    CZ 23 
    DE 5733 
    ES 336 
    FR 2 
    IE 1066 
    IT 7085 
    NL 260 
    NZ 89 
    PT 790 

    Country CallSuccess 
    AT 5662 
    BE 480 
    CH 370 
    CZ 1124 
    DE 19412 
    ES 7740 
    FR 1976 
    IE 26616 
    IT 32764 
    NL 4046 
    NZ 114 
    PT 6567 

如何将这些添加到一个布局,并最终有一个表如下所示:

Country CallSuccess fails 
AT 5662     240 
BE 480     10 
CH 370     22 
CZ 1124     112 
DE 19412    888 
ES 7740     etc.. 
FR 1976 
IE 26616 
IT 32764 
NL 4046 
NZ 114 
PT 6567 

回答

1

COUNT忽略NULL,案件吉斯NULL的隐含else条件

SELECT 
    Country, 
    count(CASE WHEN actstatus = 105 THEN status END) AS FailedCalls, 
    count(CASE WHEN actstatus = 5 THEN status END) AS GoodCalls 
FROM 
    termactivity(nolock) 
    INNER JOIN 
    termconfig(NOLOCK) ON cfgterminalID = actterminalID 
where actstatus IN (105, 5) 
GROUP BY country 
ORDER BY country 
+0

snap!我想你只是打败了我! – 2012-02-02 14:59:47

+0

捕捉!没有使用过你的史蒂夫.. – Axle 2012-02-02 15:36:36

1

我会改变你的SQL返回一个数据集是这样的。

Select Country, 
     Sum(Case When actstatus = 5 Then 1 Else 0 End) As FailedCalls, 
     Sum(Case When actstatus = 105 Then 1 Else 0 End) As SucceededCalls 
From termactivity(nolock) 
    INNER JOIN termconfig(NOLOCK) ON cfgterminalID = actterminalID 
Where actstatus IN (5, 105) 
Group By Country 
order By Country 
+0

谢谢你们..我用过答案1.但无论如何。 :) – Axle 2012-02-02 15:35:51

相关问题