如何创建数据透视表而不对列求和
这是我的查询
CREATE view pivmehis WITH ENCRYPTION
as
SELECT APPROVED, [Not Approved] as REJECT, NULL
FROM
(SELECT MgtApproval
from LeaveRequest) l
PIVOT
(
Sum (SchedId) --I DON'T WANT TO SUM THIS COLUMN
FOR MgtApproval IN
([APPROVED], [REJECT], [NULL])) as pvt
原始表结果:
MgtApproval SchedId
Approved 1
Reject 2
Null 3
Approved 4
Reject 5
Null 6
这是我想查看的结果:
Approved Reject Null
1 2 3
4 5 6
Here is my query
CREATE view pivmehis WITH ENCRYPTION
as
SELECT APPROVED, [Not Approved] as REJECT, NULL
FROM
(SELECT MgtApproval
from LeaveRequest) l
PIVOT
(
Sum (SchedId) --I DON'T WANT TO SUM THIS COLUMN
FOR MgtApproval IN
([APPROVED], [REJECT], [NULL])) as pvt
Original table results:
MgtApproval SchedId
Approved 1
Reject 2
Null 3
Approved 4
Reject 5
Null 6
This is the results I would like to view:
Approved Reject Null
1 2 3
4 5 6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PIVOT
仍然需要任何聚合函数,但这个函数保证最多聚合一列。以下是对示例数据的查询,它返回您想要的内容:
更新:
由于您提到您的列实际上是一个
位
,因此您应该使用以下语法:A
PIVOT
still need any aggregation function, but this one is guaranteed to aggregate on at most one column.Here's the query on sample data which returns exactly what you want:
Update:
Since you mentioned that your column is in fact a
bit
, you should use this syntax: