用于显示结果的SQL查询

时间:2014-11-20 18:39:10

标签: sql oracle

以下是数据库中的表格:

Product     Type1       Type2       Type3       Manufacturer
Notebook    50 Pages    100 Pages   150 Pages   KP Mills
Pen         Blue        Black       Red         Parker

SQL Query应该以下列格式显示结果:

Product     Type        Manufacturer
Notebook    50 Pages    KP Mills
Notebook    100 Pages   KP Mills
Notebook    150 Pages   KP Mills
Pen         Blue        Parker
Pen         Black       Parker
Pen         Red         Parker

1 个答案:

答案 0 :(得分:3)

select product, 
       type1 as type,
       manufacturer
from the_table
union all
select product, 
       type2,
       manufacturer
from the_table
union all
select product, 
       type3,
       manufacturer
from the_table
order by product, type;