select t.a2 from table1 t
where t.a1 = 本月
minus
select t1.a2 from table1 t1
where t1.a1 = 上月;
这样试试

解决方案 »

  1.   

    看这样:
    select * from table1 t
    where t.a1 = 本月
          and t.a2 not exist(select t1.a2
                                   from table1 t1
                                   where t1.a1 = 上月)但感觉奇怪
    select * from table1 t where t.a1 = 本月

    select t1.a2 from table1 t1 where t1.a1 = 上月
    没关系!
      

  2.   

    楼上说的很对,但是table1表要有字段a1的索引,不然两种方法运行速度差不多
      

  3.   

    --try it.
    select * from table1 t
    where t.a1 = 本月
          and not exist (select t1.a2 from table1 t1
                                   where t1.a1 = 上月 and t1.a2 = t.a2)