用union查询就可以了
先选取出上月的做为a,再选取出本月的做为b .
再将a,b做成union如果把原始的数据库表的结构说出来就可以很好的写语句了.

解决方案 »

  1.   

    select name,(case when strmonth='上月' then salary else NULL end ) as 'salary(上月)',(case when strmonth='上月' then code else NULL end) as 'code(上月)',(case when strmonth='本月' then salary else NULL end ) as 'salary(本月)',(case when strmonth='本月' then code else NULL end)  as 'code(本月)' from test --group by name试验一下,应该可以,可以就给分喔
      

  2.   

    表名:table1
    列名:
    name salary   code   mdate就这几个字段
      

  3.   

    mdate 是日期字段,通过between and 查询得到上月和本月数据