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)
这样的语句,当然这句话是不对的。谢谢。
字段: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)
这样的语句,当然这句话是不对的。谢谢。
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
.........
id as integer
scoreL as integer
scoreH as integer
end typedim NameSql() as arrayNameredim NameSql(index) as arrayNameSQLstr=......
select * from tt where id in (...) and score between minval and maxval
mao se deng kai
果然是个好方法