VB+Access表:Studens
字段:Id,Sub,Score
我现在有一查询语句(当然实际情况比这要复杂的多,这里把不相干的拿走)
select * from Studens where Id in (1,2,5,33,56,98)
主要的功能是事先把员工Id集成(1,2,5,33,56,98,.....),这样一起查询以提高效率现在的问题是如果每个员工都有他自己的查询条件,怎么把这个条件合成进行
比如:
select * from Studens where Id=1 and score>50 and score<80
select * from Studens where Id=2 and score>60 and score<90
select * from Studens where Id=5 and score>65 and score<80
select * from Studens where Id=33 and score>55 and score<70
...........
select * from Studens where Id=98 and score>40 and score<50
.............
把这些语句合成类似
select * from Studens where Id in (1,2,5,33,56,98) and score >(50,60,65,55,40) and score < (80,90,80,70,50)
这样的语句,当然这句话是不对的。谢谢。

解决方案 »

  1.   

    select * from Studens where Id=1 and score>50 and score<80
    union
    select * from Studens where Id=2 and score>60 and score<90
    union
    select * from Studens where Id=5 and score>65 and score<80
    union
    select * from Studens where Id=33 and score>55 and score<70
    .........
      

  2.   

    type arrayName
        id as integer 
        scoreL as integer 
        scoreH as integer 
    end typedim NameSql() as arrayNameredim NameSql(index) as arrayNameSQLstr=......
      

  3.   

    如果数据库为ACCESS,则有些语句不起作用
      

  4.   

    创建一个表tt(或者视图),其中包含这三列,ID,MinVal,MaxVal,然后:
    select * from tt where id in (...) and score between minval and maxval
      

  5.   

    to : boydgmx(梦霄) 
    mao se deng kai
    果然是个好方法