【问题标题】:SQL Server 2005 Business intelligence use 2 datasets one reportSQL Server 2005 商业智能使用 2 个数据集一份报告
【发布时间】:2023-03-15 11:30:02
【问题描述】:

只需要一些有关 SQL Server 2005 和 Visual Studio 2005 的帮助/建议。

基本上,我有 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 的单元格中有“5”

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

现在这两个结果都会生成带有国家名称和数字的表格,如下所示

 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

【问题讨论】:

    标签: sql-server-2005


    【解决方案1】:

    COUNT 忽略 NULL,CASE 将 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
    

    【讨论】:

    • 快!我想你只是打败了我!
    【解决方案2】:

    我会更改你的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多