3

このクエリはSQLServer2005にあり(たとえば、より便利な2008挿入メソッドのみを使用しました)、グリッド出力で(null)を0に置き換える必要があります。

とにかくこれを行うには?

4

1 に答える 1

4

関数を使用しISNULL()ます。SQL フィドルを参照してください

SELECT 'lessonid          response ->'
   , isnull([0], 0) as [0]
  , isnull([1], 0) as [1]
  , isnull([2], 0) as [2]
  , isnull([3], 0) as [3]
  , isnull([4], 0) as [4]
FROM (
    SELECT lessonid AS 'lessonid          response ->'
        ,ISNULL(response,0) as response
        ,count(response) AS respcnt
    FROM tblRChoices
    GROUP BY lessonid
        ,response
    ) TableResponse
PIVOT(SUM(respcnt) FOR response IN (
            [0]
            ,[1]
            ,[2]
            ,[3]
            ,[4]
            )) ResponsePivot
于 2012-07-12T19:40:29.467 に答える