下面我们以一个简单的例子来说明,假设有一个名为employee的表,现在我们要从其中查询数据,条件有三个,由用户动态选择,如图1所示:

其中条件A、B、C之间是与的关系,A、B、C均为动态选择,可以取其中的一个、两个或三个,也可以一个都不选,当三个条件都不选择时则认为是无条件查询,按照通常的做法,判断方法如图2所示:

这样,最终的结果有8个,即有8条查询语句,分别是
1.select * from employee;
2.select * from employee where Age =C ;
3.select * from employee where Sex=B;
4.select * from employee where Sex=B and Age=C;
5.select * from employee where Name=A;
6.select * from employee where Name=A and Age=C;
7.select * from employee where Name=A and Sex=B ;
【中国QQ站】【设为主页】【收藏本页】【打印本文】【回到顶部】【关闭此页】