有一张表,其中有本年的工资数据,其中以月份为标识分开,我想查询本月与上月的人员变动;请问,有简单的SQL语句吗?
结构如下:姓名,单位,身份证号。工资,工资月份

解决方案 »

  1.   

    本月有,上月没有的:
    select 姓名 from 表1
    where 姓名 in (select distinct 姓名 from 表1 where 月份=本月)
    and 姓名 not in (select distinct 姓名 from 表1 where 月份=上月)反之类似。
      

  2.   

    select 姓名 from 表1
    where 姓名 in (select distinct 姓名 from 表1 where 工资月份=本月)
    and 姓名 not in (select distinct 姓名 from 表1 where 工资月份=上月)
      

  3.   

    不要这么复杂吧
    select 姓名 from 表1
    where 工资月份=本月
    and 姓名 not in (select distinct 姓名 from 表1 where 工资月份=上月)
      

  4.   

    select 姓名 from 表1 where 月份=本月
    and 身份证号 not in (select 身份证号 from 表1 where 月份=上月)
      

  5.   

    同意palmkey(源水)的。
    本月有,上月没有的:
    select 姓名 from 表1
    where id in (select distinct id from 表1 where 月份=本月)
    and id not in (select distinct id from 表1 where 月份=上月)反之类似。