0

The Below Statement works perfectly. It counts all the values from region 37000 and has a computed column no. What I want to do is add several more counts where I can change the where clause for instance to 38000 or 39000. Can anyone help me out... Thanks

SELECT a.region, COUNT(*) AS [computedCol1]    
(
SELECT  DISTINCT table1.serial1, table1.serial2,
    CASE WHEN table2.serial1 IS NULL THEN 'No' ELSE 'Yes' END AS [computedCol1],
    CASE WHEN table3.serial2 IS NULL THEN 'No' ELSE 'Yes' END AS [computedCol2],
    CASE WHEN table3.serial2 IS NULL AND table2.serial1 IS NULL THEN 'No' ELSE 'Yes' END AS [computedCol3]

FROM    table1
        LEFT JOIN table2
            ON table2.serial1 = table1.serial1
        LEFT JOIN dbo.EPG
            table3.serial2 = table1.serial2
)a where region = '37000' and [computedCol1]= 'No'
    group by a.region
4

1 回答 1

3

WHERE region in ('37000','38000','39000')

当您按区域分组时,您将获得每个区域的三个不同行及其计数。

于 2012-05-31T15:48:07.150 回答