【问题标题】:SQL for joining different tables用于连接不同表的 SQL
【发布时间】:2016-10-03 16:40:31
【问题描述】:

我有以下表格:

我想编写一个显示以下结果的选择语句

我尝试加入/联合/联合所有这两个表,但我没有得到想要的输出。谁能帮帮我?

【问题讨论】:

  • 第二个表和你的问题有什么关系?你需要某种支点,没有连接也没有联合。解决方案取决于您的 Oracle 版本,您应该始终将其包含在您的问题中。
  • 请将数据粘贴为文本,这有助于测试,也有助于图像被屏蔽的人
  • 我尝试使用 pivot 但我是新手,所以我没有得到我想要的输出

标签: sql oracle select join


【解决方案1】:
select
 'group_a' as groupname
, max( case classname when 'C123' then group_a else null end)  as c123
, max( case classname when 'C456' then group_a else null end)  as c456
from table1
union all
select
 'group_b' as groupname
, max( case classname when 'C123' then group_b else null end)  as c123
, max( case classname when 'C456' then group_b else null end)  as c456
from table1
union all
select
 'group_d' as groupname
, max( case classname when 'C123' then group_d else null end)  as c123
, max( case classname when 'C456' then group_d else null end)  as c456
from table1
union all
select
 'group_e' as groupname
, max( case classname when 'C123' then group_e else null end)  as c123
, max( case classname when 'C456' then group_e else null end)  as c456
from table1

【讨论】:

    猜你喜欢
    • 2015-04-01
    • 2019-09-22
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2018-07-22
    相关资源
    最近更新 更多