表一是考核表
table1
 
id  xm     money    yue   nian
1   王三    200      2    2012
2   王四    230      2   2012
3   王三    215      3    2012
表2是人员名单
id   xm 
1    王三
2   王四表一中存放的是每个月的考核情况,要求所有人每个月都要有数据,本例中表一中2012年3月缺少王四的数据要求通过SQL语句查出某个月表一的缺少人员名单。
谢谢!!

解决方案 »

  1.   

    select name from table2 where id in(select id from table2 where id not in(select id from table1 where yue||nian='&date'))  
    看看行吗?
      

  2.   

    select xm from TB2 
      where xm not in(select distinct xm from tb1 where nian='2012' and yue='3')
      

  3.   

    select * from tablename t where t.XM='王四' and t.yue=3 and t.money is null ;
    想查其他人或者月份!把王四跟3替换下就可以了、1
      

  4.   


    select a.yue, b.xm
      from (select distinct yue from table1) a,
           (select distinct xm from table2) b
     where not exists (select 1
              from table1
             where yue = a.yue
               and xm = b.xm);这样比较复杂,也可以先查所有人所有月,然后MINUS一下TABLE1里有的记录