MySql怎么实现多条件查询呢?我有五种条件。关键是我想知道查询语句该怎么精简。

有的方法用是数组。不知道怎么写。。。

给你思路,具体你自己去写:
1.你这个是有二类条件:必选的:前二个2选1;
后面三个条件是可选的,选全部等于没选就没必要加这个条件,关键字没填的话等同;
所以你其实就是1-4个条件。
2.实现建议用存储过程,参数根据实际情况传递,条件越多查询越慢,越慢(耗cpu和io)的条件要放在语句的最后。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-24
如果是PHP,建议使用ThinkPHP框架吧。
$where['condition1']=$_POST['condition1'];
$where['condition2']=$_POST['condition2'];
$where['condition3']=$_POST['condition3'];
$where['condition4']=$_POST['condition4'];
$where['condition5']=$_POST['condition5'];
$aa=M('Aa');
$aa->where($where)->select();