如何在SQL中添加总计作为最后一行? [英] How do I add a total as the last row in my sql?
本文介绍了如何在SQL中添加总计作为最后一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试显示总计"行,该行将计算计数"列的总和.下面的代码将包含两列:环境"和计数".
I'm trying to display a row, 'Total', that will do a sum of the Count column. The following code will have two columns, Environment and Count.
select
case
when env is null THEN 'Unknown'
else env
end,
count(*) as Count
from env_table
group by env
order by env
/
我想要的输出:
Windows 200
Windows 200
Linux 120
Linux 120
总计320
正如您在上面看到的,我想做的是在末尾添加一个称为总计"的行,该行实际上将执行SUM(count(*)).正确的语法是什么?谢谢!
As you can see above, what I would like to do is add a row called "Total" at the end that would essentially do a SUM(count(*)). What is the proper syntax to do this? Thanks!
推荐答案
使用 查看全文