简体   繁体   English

用于连接不同表的SQL

[英]SQL for joining different tables

I have the following tables : 我有以下表格:

在此处输入图片说明

在此处输入图片说明

I want to write a Select Statment that show the following result 我想写一个显示以下结果的选择语句

在此处输入图片说明

I Tried to Join/ Union/Union All the two table but I dont get the desird output. 我试图加入/联合/联合所有两个表,但我没有得到理想的输出。 Can anyone help me with it? 有人可以帮我吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM