sql - oracle如何合并两列
问题描述
我有一个问题
select
city,
month,
month_number,
sum(totalcount) as totalcount,
sum(total_value) total_value
from
(
select
city,
to_char( testdate, 'Mon') month,
to_number( to_char( testdate, 'mm' ) ) month_number,
count( totalcount ) totalcount,
sum( total_value ) total_value
from
testtable
group by
city,
testdate
)
group by
city,
month,
month_number
order by
1,3
将结果作为图像 1,如何修改可以将结果作为图像 2 的查询?
解决方案
在 group by 中使用 Oracle ROLLUP 函数来达到预期的结果。
select
city,
month,
month_number,
sum(totalcount) as totalcount,
sum(total_value) total_value
from
(
select
city,
to_char( testdate, 'Mon') month,
to_number( to_char( testdate, 'mm' ) ) month_number,
count( totalcount ) totalcount,
sum( total_value ) total_value
from
testtable
group by
city,
testdate
)
group by
city,
ROLLUP (month,month_number)
order by
1,3
推荐阅读
- r - 为什么 geom_text_repel() 忽略尺寸美学?
- django - 我的 Bollean 字段之一显示为选择(未知/是/否)而不是复选框
- pandas - 从 Spark UDF 调用时,pandas to_csv 函数未写入 Blob 存储
- regex - Oniguruma 正则表达式条件组捕获
- javascript - 通过键匹配两个对象,并从一个对象返回一个具有键和值的新对象
- amazon-web-services - 如何使用白名单后端主机 IP 创建 GCP 负载平衡
- scripting - 如何在没有大字符串的情况下创建资源字符串?
- android - 如何在 RecyclerView 适配器中的 ClickListener 上显示 AlertDialog
- javascript - 在 react.js 中使用 three.js 创建 WebXR 应用程序时,我不断看到“XRWebGLLayer”未定义 no-undef
- c - C 用户输入被跳过