工资类型表:
编号 类型
1    基本工资
2    奖金
3    社会保险
4    其他扣款工资表
员工编号   工资类型     工资
张三       1            3000
张三       2            5000
张三       3            300
张三       4            100
李四       1            3500
李四       2            5000
李四       3            300
李四       4            100我要得到如下的效果:
张三          3000          5000        300      100
李四          3500          5000        300      100
不知道SELECT 语句该怎么写?望前辈们指教.
谢谢

解决方案 »

  1.   

    select t.*, t.rowid from nc_examineeinfo t where xm  in ('王彦松','徐洋')
      

  2.   

    SQL> create table tmp_gz_t (id number(1),name varchar2(20));Table createdSQL> insert into tmp_gz_t values(1, '基本工资');1 row insertedSQL> insert into tmp_gz_t values(2, '奖金');1 row insertedSQL> commit;Commit completeSQL> create table tmp_gz (nname varchar2(10),id number(1),gz number(5));Table createdSQL> insert into tmp_gz values('张三',  1,3000);1 row insertedSQL> insert into tmp_gz values('张三',       2,            5000);1 row insertedSQL> insert into tmp_gz values('张三',       3,            300);1 row insertedSQL> insert into tmp_gz values('张三',       4,            100);1 row insertedSQL> insert into tmp_gz values('李四',       1,            3500);1 row insertedSQL> commit;Commit completeSQL> select nname,sum(decode(id,1,gz,0)) "1",
      2  sum(decode(id,2,gz,0)) "2",
      3  sum(decode(id,3,gz,0)) "3",
      4  sum(decode(id,4,gz,0)) "4"
      5  from tmp_gz
      6  group by nname;NNAME               1          2          3          4
    ---------- ---------- ---------- ---------- ----------
    李四             3500          0          0          0
    张三             3000       5000        300        100
      

  3.   

    ID       TYPE     SALARY
    -----    -------  -----------
    1.00 1 10.00
    1.00 2 100.00
    1.00 3 1,000.00
    1.00 4 10,000.00
    2.00 1 20.00
    2.00 2 200.00
    2.00 3 2,000.00
    2.00 4 20,000.00select  员工编号, sum(decode(工资类型,1, 工资,null)) "1", 
                      sum(decode(工资类型,2, 工资,null)) "2", 
                      sum(decode(工资类型,3, 工资,null)) "3",
    sum(decode(工资类型,4, 工资,null)) "4" 
    from tab
    group by 员工编号ID       1        2        3         4
    -----    -------  -------  --------- -----------
    1 10.00 100.00 1,000.00 10,000.00
    2 20.00 200.00 2,000.00 20,000.00
      

  4.   

    liucuiqiang(小强) 能详细的讲解一下cross join应该怎样写这条select吗?其他的几个好像都不行的,应为我的工资类型表是动态的,随时都会增加或删减的.
      

  5.   

    http://community.csdn.net/Expert/topic/5022/5022497.xml?temp=.3983576
      

  6.   

    是在做报表吗?用什么工具做,这很重要。
    就我所知,REPORT BUILDER支持交叉报表,可以实现该功能。如果类型表是不定的,想要行转列,必须使用存储过程或函数,想一条SQL解决
    基本上不可能。
      

  7.   

    Eric_1999(╙@^@╜۩) 的是正解,行列转换的简单sql
      

  8.   

    Eric_1999(╙@^@╜۩) 的对于工资类型表是固定的来说是可以的,关键我的工资类型的表可能会随时增加或删除记录的.
      

  9.   

    select  select a.员工编号,a.基本工资,b.奖金,c.社会保险,d.其他扣款 from 
    (select 员工编号,工资 as 基本工资  from where 工资类型='基本工资') a,
    (select 员工编号,工资 as 奖金  from where 工资类型='奖金') b,
    (select 员工编号,工资 as 社会保险  from where 工资类型='社会保险') c,
    (select 员工编号,工资 as 其他扣款  from where 工资类型='其他扣款') d
    where a.员工编号=b.员工编号 and 
          a.员工编号=c.员工编号 and 
          a.员工编号=d.员工编号;
      

  10.   

    如果你有N个工资项目,SQL语句请运态生成,SQL语句会跟着项目表的变化而变化.