数据库列转行实现

发布时间:2026/10/23 4:07:30
数据库列转行实现 昨天遇到一个需求给的文档内容是机构职能说明工时信息如图因为需要做成配置表数据进行后续计算且需要用机构职能说明进行关联映射所以需要进行一定程度的转置。转置完成效果如图实现逻辑如下--数据转置逻辑纯原创with a as(select 人力资源 as 职能说明,0.2 as 安徽,null as 北京,0.3 as 甘肃,0.6 as 广东,0.3 as 贵州,0.3 as 河北,0.4 as 河南,2 as 江苏,0.4 as 宁波,0.5 as 青岛,0.6 as 山东,0.4 as 山西,0.1 as 陕西,1.1 as 上海,0.7 as 深圳,0.4 as 四川,0.25 as 云南,0.7 as 浙江,1.85 as 重庆union all select 薪酬管理,0.3,null,0.4,0.5,0.4,0.4,0.3,0.6,0.4,0.7,0.6,0.4,0.5,0.55,0.8,0.4,0.25,0.4,2.05union all select 绩效考核,1.1,null,0.6,0.4,0.2,0.3,0.2,0.6,0.4,0.7,0.6,0.4,0.7,0.6,0.4,0.4,0.1,0.6,0.65union all select 教育培训,0.2,null,0.2,0.2,0.1,0.2,0.1,0.3,0.2,0.2,0.2,0.3,0.1,0.1,0.1,0.3,0.2,0.1,1.85union all select 综合管理,0.7,null,0.2,0.5,0.2,0.5,0.3,1,1,1,1,0.3,1,0.55,0.8,0.8,1.3,0.8,3.85union all select 后勤管理,0.6,null,0.2,0.6,0.2,0.5,0.2,1,0.7,0.7,1,0.3,0.8,0.7,0.8,0.6,0.3,0.4,3.6union all select 集中采购,0.2,null,0.2,0.2,0.2,0.1,0.1,0.3,0.3,0.5,0.6,0.3,0.3,0.35,0.4,0.1,0,0.1,0.6union all select 督查督办,0.2,null,0.1,0.1,0.1,0.2,0.1,0.4,null,0.1,0.5,null,0.4,0.1,0,0.2,0.1,0.2,0.85union all select 文秘,0.3,null,0.4,0.4,0.2,0.2,0.2,0.4,0.4,0.4,0.6,0.3,0.8,0.35,0.5,0.5,0.3,0.5,0.35union all select 宣传,0.2,null,0.4,0.5,0.1,0.3,0.1,0.4,0.2,0.2,0.3,0.3,0.3,0.1,0.5,0.3,0.2,0.2,1.35union all select 风险合规,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,nullunion all select 党建,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null),b as (select regexp_split_to_table(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,,) aa,a.*from a),c as (select aa,casewhen aa 1 then 安徽when aa 2 then 北京when aa 3 then 甘肃when aa 4 then 广东when aa 5 then 贵州when aa 6 then 河北when aa 7 then 河南when aa 8 then 江苏when aa 9 then 宁波when aa 10 then 青岛when aa 11 then 山东when aa 12 then 山西when aa 13 then 陕西when aa 14 then 上海when aa 15 then 深圳when aa 16 then 四川when aa 17 then 云南when aa 18 then 浙江when aa 19 then 重庆end 机构,职能说明,casewhen 职能说明人力资源 then 01when 职能说明薪酬管理 then 02when 职能说明绩效考核 then 03when 职能说明教育培训 then 04when 职能说明综合管理 then 05when 职能说明后勤管理 then 06when 职能说明集中采购 then 07when 职能说明督查督办 then 08when 职能说明文秘 then 09when 职能说明宣传 then 10when 职能说明风险合规 then 11when 职能说明党建 then 12end rr,casewhen aa 1 thencasewhen 职能说明人力资源 then 安徽::numeric(16,2)when 职能说明薪酬管理 then 安徽::numeric(16,2)when 职能说明绩效考核 then 安徽::numeric(16,2)when 职能说明教育培训 then 安徽::numeric(16,2)when 职能说明综合管理 then 安徽::numeric(16,2)when 职能说明后勤管理 then 安徽::numeric(16,2)when 职能说明集中采购 then 安徽::numeric(16,2)when 职能说明督查督办 then 安徽::numeric(16,2)when 职能说明文秘 then 安徽::numeric(16,2)when 职能说明宣传 then 安徽::numeric(16,2)when 职能说明风险合规 then 安徽::numeric(16,2)when 职能说明党建 then 安徽::numeric(16,2)endwhen aa 2 thencasewhen 职能说明人力资源 then 北京::numeric(16,2)when 职能说明薪酬管理 then 北京::numeric(16,2)when 职能说明绩效考核 then 北京::numeric(16,2)when 职能说明教育培训 then 北京::numeric(16,2)when 职能说明综合管理 then 北京::numeric(16,2)when 职能说明后勤管理 then 北京::numeric(16,2)when 职能说明集中采购 then 北京::numeric(16,2)when 职能说明督查督办 then 北京::numeric(16,2)when 职能说明文秘 then 北京::numeric(16,2)when 职能说明宣传 then 北京::numeric(16,2)when 职能说明风险合规 then 北京::numeric(16,2)when 职能说明党建 then 北京::numeric(16,2)endwhen aa 3 thencasewhen 职能说明人力资源 then 甘肃::numeric(16,2)when 职能说明薪酬管理 then 甘肃::numeric(16,2)when 职能说明绩效考核 then 甘肃::numeric(16,2)when 职能说明教育培训 then 甘肃::numeric(16,2)when 职能说明综合管理 then 甘肃::numeric(16,2)when 职能说明后勤管理 then 甘肃::numeric(16,2)when 职能说明集中采购 then 甘肃::numeric(16,2)when 职能说明督查督办 then 甘肃::numeric(16,2)when 职能说明文秘 then 甘肃::numeric(16,2)when 职能说明宣传 then 甘肃::numeric(16,2)when 职能说明风险合规 then 甘肃::numeric(16,2)when 职能说明党建 then 甘肃::numeric(16,2)endwhen aa 4 thencasewhen 职能说明人力资源 then 广东::numeric(16,2)when 职能说明薪酬管理 then 广东::numeric(16,2)when 职能说明绩效考核 then 广东::numeric(16,2)when 职能说明教育培训 then 广东::numeric(16,2)when 职能说明综合管理 then 广东::numeric(16,2)when 职能说明后勤管理 then 广东::numeric(16,2)when 职能说明集中采购 then 广东::numeric(16,2)when 职能说明督查督办 then 广东::numeric(16,2)when 职能说明文秘 then 广东::numeric(16,2)when 职能说明宣传 then 广东::numeric(16,2)when 职能说明风险合规 then 广东::numeric(16,2)when 职能说明党建 then 广东::numeric(16,2)endwhen aa 5 thencasewhen 职能说明人力资源 then 贵州::numeric(16,2)when 职能说明薪酬管理 then 贵州::numeric(16,2)when 职能说明绩效考核 then 贵州::numeric(16,2)when 职能说明教育培训 then 贵州::numeric(16,2)when 职能说明综合管理 then 贵州::numeric(16,2)when 职能说明后勤管理 then 贵州::numeric(16,2)when 职能说明集中采购 then 贵州::numeric(16,2)when 职能说明督查督办 then 贵州::numeric(16,2)when 职能说明文秘 then 贵州::numeric(16,2)when 职能说明宣传 then 贵州::numeric(16,2)when 职能说明风险合规 then 贵州::numeric(16,2)when 职能说明党建 then 贵州::numeric(16,2)endwhen aa 6 thencasewhen 职能说明人力资源 then 河北::numeric(16,2)when 职能说明薪酬管理 then 河北::numeric(16,2)when 职能说明绩效考核 then 河北::numeric(16,2)when 职能说明教育培训 then 河北::numeric(16,2)when 职能说明综合管理 then 河北::numeric(16,2)when 职能说明后勤管理 then 河北::numeric(16,2)when 职能说明集中采购 then 河北::numeric(16,2)when 职能说明督查督办 then 河北::numeric(16,2)when 职能说明文秘 then 河北::numeric(16,2)when 职能说明宣传 then 河北::numeric(16,2)when 职能说明风险合规 then 河北::numeric(16,2)when 职能说明党建 then 河北::numeric(16,2)endwhen aa 7 thencasewhen 职能说明人力资源 then 河南::numeric(16,2)when 职能说明薪酬管理 then 河南::numeric(16,2)when 职能说明绩效考核 then 河南::numeric(16,2)when 职能说明教育培训 then 河南::numeric(16,2)when 职能说明综合管理 then 河南::numeric(16,2)when 职能说明后勤管理 then 河南::numeric(16,2)when 职能说明集中采购 then 河南::numeric(16,2)when 职能说明督查督办 then 河南::numeric(16,2)when 职能说明文秘 then 河南::numeric(16,2)when 职能说明宣传 then 河南::numeric(16,2)when 职能说明风险合规 then 河南::numeric(16,2)when 职能说明党建 then 河南::numeric(16,2)endwhen aa 8 thencasewhen 职能说明人力资源 then 江苏::numeric(16,2)when 职能说明薪酬管理 then 江苏::numeric(16,2)when 职能说明绩效考核 then 江苏::numeric(16,2)when 职能说明教育培训 then 江苏::numeric(16,2)when 职能说明综合管理 then 江苏::numeric(16,2)when 职能说明后勤管理 then 江苏::numeric(16,2)when 职能说明集中采购 then 江苏::numeric(16,2)when 职能说明督查督办 then 江苏::numeric(16,2)when 职能说明文秘 then 江苏::numeric(16,2)when 职能说明宣传 then 江苏::numeric(16,2)when 职能说明风险合规 then 江苏::numeric(16,2)when 职能说明党建 then 江苏::numeric(16,2)endwhen aa 9 thencasewhen 职能说明人力资源 then 宁波::numeric(16,2)when 职能说明薪酬管理 then 宁波::numeric(16,2)when 职能说明绩效考核 then 宁波::numeric(16,2)when 职能说明教育培训 then 宁波::numeric(16,2)when 职能说明综合管理 then 宁波::numeric(16,2)when 职能说明后勤管理 then 宁波::numeric(16,2)when 职能说明集中采购 then 宁波::numeric(16,2)when 职能说明督查督办 then 宁波::numeric(16,2)when 职能说明文秘 then 宁波::numeric(16,2)when 职能说明宣传 then 宁波::numeric(16,2)when 职能说明风险合规 then 宁波::numeric(16,2)when 职能说明党建 then 宁波::numeric(16,2)endwhen aa 10 thencasewhen 职能说明人力资源 then 青岛::numeric(16,2)when 职能说明薪酬管理 then 青岛::numeric(16,2)when 职能说明绩效考核 then 青岛::numeric(16,2)when 职能说明教育培训 then 青岛::numeric(16,2)when 职能说明综合管理 then 青岛::numeric(16,2)when 职能说明后勤管理 then 青岛::numeric(16,2)when 职能说明集中采购 then 青岛::numeric(16,2)when 职能说明督查督办 then 青岛::numeric(16,2)when 职能说明文秘 then 青岛::numeric(16,2)when 职能说明宣传 then 青岛::numeric(16,2)when 职能说明风险合规 then 青岛::numeric(16,2)when 职能说明党建 then 青岛::numeric(16,2)endwhen aa 11 thencasewhen 职能说明人力资源 then 山东::numeric(16,2)when 职能说明薪酬管理 then 山东::numeric(16,2)when 职能说明绩效考核 then 山东::numeric(16,2)when 职能说明教育培训 then 山东::numeric(16,2)when 职能说明综合管理 then 山东::numeric(16,2)when 职能说明后勤管理 then 山东::numeric(16,2)when 职能说明集中采购 then 山东::numeric(16,2)when 职能说明督查督办 then 山东::numeric(16,2)when 职能说明文秘 then 山东::numeric(16,2)when 职能说明宣传 then 山东::numeric(16,2)when 职能说明风险合规 then 山东::numeric(16,2)when 职能说明党建 then 山东::numeric(16,2)endwhen aa 12 thencasewhen 职能说明人力资源 then 山西::numeric(16,2)when 职能说明薪酬管理 then 山西::numeric(16,2)when 职能说明绩效考核 then 山西::numeric(16,2)when 职能说明教育培训 then 山西::numeric(16,2)when 职能说明综合管理 then 山西::numeric(16,2)when 职能说明后勤管理 then 山西::numeric(16,2)when 职能说明集中采购 then 山西::numeric(16,2)when 职能说明督查督办 then 山西::numeric(16,2)when 职能说明文秘 then 山西::numeric(16,2)when 职能说明宣传 then 山西::numeric(16,2)when 职能说明风险合规 then 山西::numeric(16,2)when 职能说明党建 then 山西::numeric(16,2)endwhen aa 13 thencasewhen 职能说明人力资源 then 陕西::numeric(16,2)when 职能说明薪酬管理 then 陕西::numeric(16,2)when 职能说明绩效考核 then 陕西::numeric(16,2)when 职能说明教育培训 then 陕西::numeric(16,2)when 职能说明综合管理 then 陕西::numeric(16,2)when 职能说明后勤管理 then 陕西::numeric(16,2)when 职能说明集中采购 then 陕西::numeric(16,2)when 职能说明督查督办 then 陕西::numeric(16,2)when 职能说明文秘 then 陕西::numeric(16,2)when 职能说明宣传 then 陕西::numeric(16,2)when 职能说明风险合规 then 陕西::numeric(16,2)when 职能说明党建 then 陕西::numeric(16,2)endwhen aa 14 thencasewhen 职能说明人力资源 then 上海::numeric(16,2)when 职能说明薪酬管理 then 上海::numeric(16,2)when 职能说明绩效考核 then 上海::numeric(16,2)when 职能说明教育培训 then 上海::numeric(16,2)when 职能说明综合管理 then 上海::numeric(16,2)when 职能说明后勤管理 then 上海::numeric(16,2)when 职能说明集中采购 then 上海::numeric(16,2)when 职能说明督查督办 then 上海::numeric(16,2)when 职能说明文秘 then 上海::numeric(16,2)when 职能说明宣传 then 上海::numeric(16,2)when 职能说明风险合规 then 上海::numeric(16,2)when 职能说明党建 then 上海::numeric(16,2)endwhen aa 15 thencasewhen 职能说明人力资源 then 深圳::numeric(16,2)when 职能说明薪酬管理 then 深圳::numeric(16,2)when 职能说明绩效考核 then 深圳::numeric(16,2)when 职能说明教育培训 then 深圳::numeric(16,2)when 职能说明综合管理 then 深圳::numeric(16,2)when 职能说明后勤管理 then 深圳::numeric(16,2)when 职能说明集中采购 then 深圳::numeric(16,2)when 职能说明督查督办 then 深圳::numeric(16,2)when 职能说明文秘 then 深圳::numeric(16,2)when 职能说明宣传 then 深圳::numeric(16,2)when 职能说明风险合规 then 深圳::numeric(16,2)when 职能说明党建 then 深圳::numeric(16,2)endwhen aa 16 thencasewhen 职能说明人力资源 then 四川::numeric(16,2)when 职能说明薪酬管理 then 四川::numeric(16,2)when 职能说明绩效考核 then 四川::numeric(16,2)when 职能说明教育培训 then 四川::numeric(16,2)when 职能说明综合管理 then 四川::numeric(16,2)when 职能说明后勤管理 then 四川::numeric(16,2)when 职能说明集中采购 then 四川::numeric(16,2)when 职能说明督查督办 then 四川::numeric(16,2)when 职能说明文秘 then 四川::numeric(16,2)when 职能说明宣传 then 四川::numeric(16,2)when 职能说明风险合规 then 四川::numeric(16,2)when 职能说明党建 then 四川::numeric(16,2)endwhen aa 17 thencasewhen 职能说明人力资源 then 云南::numeric(16,2)when 职能说明薪酬管理 then 云南::numeric(16,2)when 职能说明绩效考核 then 云南::numeric(16,2)when 职能说明教育培训 then 云南::numeric(16,2)when 职能说明综合管理 then 云南::numeric(16,2)when 职能说明后勤管理 then 云南::numeric(16,2)when 职能说明集中采购 then 云南::numeric(16,2)when 职能说明督查督办 then 云南::numeric(16,2)when 职能说明文秘 then 云南::numeric(16,2)when 职能说明宣传 then 云南::numeric(16,2)when 职能说明风险合规 then 云南::numeric(16,2)when 职能说明党建 then 云南::numeric(16,2)endwhen aa 18 thencasewhen 职能说明人力资源 then 浙江::numeric(16,2)when 职能说明薪酬管理 then 浙江::numeric(16,2)when 职能说明绩效考核 then 浙江::numeric(16,2)when 职能说明教育培训 then 浙江::numeric(16,2)when 职能说明综合管理 then 浙江::numeric(16,2)when 职能说明后勤管理 then 浙江::numeric(16,2)when 职能说明集中采购 then 浙江::numeric(16,2)when 职能说明督查督办 then 浙江::numeric(16,2)when 职能说明文秘 then 浙江::numeric(16,2)when 职能说明宣传 then 浙江::numeric(16,2)when 职能说明风险合规 then 浙江::numeric(16,2)when 职能说明党建 then 浙江::numeric(16,2)endwhen aa 19 thencasewhen 职能说明人力资源 then 重庆::numeric(16,2)when 职能说明薪酬管理 then 重庆::numeric(16,2)when 职能说明绩效考核 then 重庆::numeric(16,2)when 职能说明教育培训 then 重庆::numeric(16,2)when 职能说明综合管理 then 重庆::numeric(16,2)when 职能说明后勤管理 then 重庆::numeric(16,2)when 职能说明集中采购 then 重庆::numeric(16,2)when 职能说明督查督办 then 重庆::numeric(16,2)when 职能说明文秘 then 重庆::numeric(16,2)when 职能说明宣传 then 重庆::numeric(16,2)when 职能说明风险合规 then 重庆::numeric(16,2)when 职能说明党建 then 重庆::numeric(16,2)endend 工时from b)select 机构,职能说明,工时 from c order by aa::int,rr

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询