就是由用户根据几个关键字段增加了许多组合条件至表中,然后我现在有一条数据想判断是否符合条件表里的所有查询条件。
比如:
      年龄(age)   身高(height)
       18         170
       17         150
       --         110     而我现在表tableA中有一个年龄16岁,身高110是否在以上所有的条件内?最直观的办法就是用如下查询语句:
   select count(*) from tableA where age=18 and height=170 or age=17 and height=150 or height=110
但该办法太复杂,请教各位高手有其它解新决办法吗?多谢了!

解决方案 »

  1.   

    lz的or用法应该不对吧。select count(1) from tableA where (case when age between 17 and 18 then 1 else 0)+(case when height between 110 and 170 then 1 else 0)=0;不知道这样查出来的结果是否是你想要的。这句sql可以查出age不在17-18之间,并且height不在110-170之间的数据
      

  2.   


    select count(*) from tableA where height=110 and age=16;--如>=1,则说明此表中有,否则,表中没有年龄16岁且身高为110cm的人员。
      

  3.   

    select × from tablea where exists(select 1 from tablea where age=16 and height=110);
      

  4.   

    select * from tablea where exists(select 1 from tablea where age=16 and height=110);
      

  5.   

    查出2列的最低值,再拿2个最低值作为条件 去count是否有记录