create table emp(
id int,
name varchar(32),
m1 int,
m2 int,
m3 int,
m4 int,
m5 int,
m6 int,
m7 int,
m8 int,
m9 int,
m10 int,
m11 int,
m12 int
);insert into emp values(1,'tang',1,2,3,4,5,6,7,8,9,10,11,12);注意:表为员工一年工资的信息表,m1表示1月的工资,m2表示2月的工资,。m12表示12月的工资。要求查询的结果为:
编号 姓名 工资
1 tang 1
1 tang 2
1 tang 3
..................
..................
..................
1 tang 12
要求用一条SQL语句查出来,跪求答案

解决方案 »

  1.   

    select id, name, m1 from emp 
    union all
    select id, name, m2 from emp
    union all
    select id, name, m3 from emp 
    union all
    select id, name, m4 from emp 
    union all
    select id, name, m5 from emp;后面自己加吧
      

  2.   

    oracle列转行总结:http://blog.chinaunix.net/u/22151/showart_322007.html
      

  3.   

    select id, name, m1 as m from emp 
    union all 
    select id, name, m2 as m  from emp 
    union all 
    select id, name, m3 as m  from emp 
    union all 
    select id, name, m4  as m from emp 
    union all 
    select id, name, m5  as m from emp
    union all 
    select id, name, m6  as m from emp
    union all 
    select id, name, m7  as m from emp
    union all 
    select id, name, m8  as m from emp
    union all 
    select id, name, m9  as m from emp
    union all 
    select id, name, m10  as m from emp
    union all 
    select id, name, m11  as m from emp
    union all 
    select id, name, m12  as m from emp
    order by id,m