SQL Server 2005用0填充数据透视表 [英] SQL Server 2005 fill pivot table with 0s

查看:73
本文介绍了SQL Server 2005用0填充数据透视表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2005中具有此查询(我使用了更方便的2008年插入方法方法(仅用于示例),并且我需要在网格输出中将(null)替换为0.

I have this query in SQL Server 2005 (I used the more convenient 2008 insert method for example only) and I need the (null) to be replaced with 0 in the grid output.

是否要这样做?

推荐答案

您将使用 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

这篇关于SQL Server 2005用0填充数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆