一个表T中判断2个字段,(a字段和b字段)
现在想查询这样的结果:查询在T表中a不等于X(一个数据集),并且b不等于Y(一个数据集)的记录,需要联合判断
where条件怎么写
where a not in(X) and b not in(Y) 这样写是不对的

解决方案 »

  1.   

    这个意思吗?如果X和Y是一个字段的值的话 ..
    where a <> 'X'
      and b <> 'Y'
      

  2.   

     不知道,你具体要什么东东.
      不过如果你的是9i以上版本(包涵9i), 则可以如下查询
       select * from Ytab where (a,b) not in (select x,y from YourView) .
       
      

  3.   

    表1columnA  columnB  columnC(数值)     RQ
    单位1       地点1       10         2007-09-01
    单位1       地点1       20         2007-09-01
    单位2       地点1       10         2007-09-01
    单位2       地点2       10         2007-09-01表2 为根据表1统计的结果(group by columnA,columnB)columnA  columnB  columnC(数值)     RQ
    单位1       地点1       30         2007-09-01
    单位2       地点1       10         2007-09-01
    单位2       地点2       10         2007-09-01现在要求当表1删除一条数据
    比如删除 delete from 表1 where columnA=单位2 and columnB=地点1 后
    根据表1的数据判断删除表2中含有columnA 等于单位2并且columnB等于地点1的数据 
    删除后
    表1columnA  columnB  columnC(数值)     RQ
    单位1       地点1       10         2007-09-01
    单位1       地点1       20         2007-09-01
    单位2       地点2       10         2007-09-01表2 columnA  columnB  columnC(数值)     RQ
    单位1       地点1       30         2007-09-01
    单位2       地点1       10         2007-09-01
    单位2       地点2       10         2007-09-01
    但是因为表1数据被删除后不能找到单位2和地点1的字段,只能通过已有的数据去删除
    就是查询表2中的数据是否在表1中有对应的记录,如果没有记录则删除表2的数据
      

  4.   

    建立一个触发器阿
    create or replace trigger del_table
    after for delete on 表1
    for each row
    begin
    delete from 表2 where    columnA=:old.columnA   and   columnB=:old.columeB
    end del_table;
    :old.columnA,:old.columnB就是删除的表1的相应的字段
    试验下了
      

  5.   

    hehe 多谢了 3楼结果就ok 我结贴了