网站首页 > 技术文章 正文
原始需求:逐条统计的关联结果集;通过union all 合并结果集合 ,group by 分组,通过sum统计结果集;
增强需求: 需要将逐条统计的结果进行行转列的操作
select *
from (select s.jgmc, r.xsh, r.xb, sum(r.cws) as cws
from (select a.xsh, a.xb, a.cws
from yxxt_ssb a
where nvl(a.sfhq, '否') <> '是'
union all
select c.xsh, b.xb, c.fpme as cws
from yxxt_ssb b
left join yxxt_yxssmefbb c
on b.sslh = c.sslh
and b.fjh = c.fjh
where b.sfhq = '是') r
left join yxxt_code_jgb s
on r.xsh = s.jgdm
where r.xsh is not null
group by s.jgmc, r.xsh, r.xb) g
pivot(sum(g.cws)
for xb in('男' as boyrs, '女' as grilrs))
- pivot(sum(g.cws) for xb in('男' as boyrs, '女' as grilrs)) 中的
①xb前面不能加别名!
②'男' as boyrs 中的 boyrs 不能添加单引号!
- 返回的 * 也不能加别名;
猜你喜欢
- 2025-07-23 欧莱雅SAP系统成功合并(欧莱雅corp部门)
- 2025-07-23 SQL 逻辑处理核心知识点全解析,从入门到精通看这篇就够了!
- 2024-10-25 Skydance宣布与派拉蒙合并 将成立价值280亿美元的“新派拉蒙”
- 2024-10-25 Oracle批量、大量Update方法总结 oracle批量更新语句
- 2024-10-25 Oracle 20c 新特性:缺省的只读 Oracle HOME 支持
- 2024-10-25 Oracle提高SQL执行效率的三种方法
- 2024-10-25 Oracle生成不重复字符串 sys_guid()
- 2024-10-25 oracle Merge Into 用法 oracle中merge into的理解
- 2024-10-25 如何通过云效Codeup完成代码合并 云效和码云
- 2024-10-25 SQL MERGE语句详解 sql的merge命令
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- oracle面试 (55)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)