SQL枢轴中的总数
我想让电子表格喜欢总计我拥有的SQL枢轴。下面的工作正常,以枢轴格式显示无小计的值。如果有一种方法可以同时获得行&总数的很棒。如果不是,那么至少在底部的总数就可以了。
SELECT *
FROM (SELECT period, status
FROM tasks )
PIVOT
(
COUNT(status)
FOR status IN ('Completed' AS "Completed",
'WIP' AS "WIP",
'Not Started' AS "Not Started")
)
ORDER BY period
I would like to get spreadsheet like to totals to this SQL Pivot I have. Below works fine to display the values in pivot format without subtotals. If there is a way to get both row & column total's that would be great. If not, at least total at the bottom would be fine.
SELECT *
FROM (SELECT period, status
FROM tasks )
PIVOT
(
COUNT(status)
FOR status IN ('Completed' AS "Completed",
'WIP' AS "WIP",
'Not Started' AS "Not Started")
)
ORDER BY period
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
lollup
和有条件的聚合:对于示例数据:
输出:输出:
db<> gt; fiddle 在这里
Rather than using
PIVOT
, you can useROLLUP
and conditional aggregation:Which, for the sample data:
Outputs:
db<>fiddle here