sql判断不存字段值,用查询语并显示结果表内容是:
peoid date                 type
                               
0001  2006-11-01 08:10:25  消费
0001  2006-11-02 08:10:25  消费
0001  2006-11-02 08:10:25  消费
0001  2006-11-03 08:10:25  消费
0001  2006-11-15 09:10:25  补贴
0002  2006-11-08 08:10:25  消费
0002  2006-11-09 08:10:25  存款
0003  2006-11-10 08:10:25  消费
0004  2006-11-11 08:10:25  存款
0004  2006-11-13 08:10:25  消费
0004  2006-11-15 09:10:25  补贴
0003  2006-11-16 12:10:25  消费
判断出不存type="补贴"的peoid,查询结果是:peoid0002
0003

解决方案 »

  1.   

    select distinct peoid from tb where peoid not in 
    (select distinct peoid from tb where type='补贴')
      

  2.   

    select distinct peoid from table where peoid not in 
    ( select distinct peoid from tale where type='补贴')
      

  3.   

    select distinct peoid from table where peoid not in 
    ( select distinct peoid from table where type='补贴')
      

  4.   

    select * from T where peoid in(select distinct peoid from T where type='补贴')
      

  5.   

    --錯了, 改改select * from T where peoid not in(select distinct peoid from T where type='补贴')
      

  6.   

    SELECT DISTINCT peoid FROM TableName A WHERE NOT EXISTS(SELECT 1 FROM TableName B WHERE B.peoid=A.peoid AND type='补贴')