mysql多重条件查询的问题
有3个条件,希望实现的功能:输入条件一,查询出符合条件一的结果;输入条件二,查询出符合条件二的结果;输入条件三,查询出符合条件三的结果;输入条件一,二,查询出符合条件一、二的结果;输入条件一,三,查询出符合条件一、三的结果;输入条件二,三,查询出符合条件二、三的结果;输入条件一、二、三,查询出符合条件一、二。三的结果;代码贴出,一共七个表,不知道后面的条件怎么写?这个代码能优化么?真心求解!!
$result = mysql_query("select m.tablemode,m.tablemodenote,c.tablechannel,o.tableoperator
from mode_table as m,mode_operator_relation as mo,operator_table as o,mode_provider_relation as mp,
provider_table as p,channel_provider_relation as cp,channel_table as c
where mo.tablemodeid = m.tablemodeid
and o.tableopeid = mo.tableopeid
and mp.tablemodeid = m.tablemodeid
and mp.tableproid = p.tableproid
and p.tableproid = cp.tableproid
and cp.tablechaid = c.tablechaid
and 条件1 条件2 条件3
if(条件1){
$sql . = " and xxx1 ";
}
if(条件2){
$sql . = " and xxx2 ";
}
if(条件3){
$sql . = " and xxx3 ";
}
sql语句优化 遵循explain
if(条件1){
$sql . = " and xxx1 ";
}
if(条件2){
$sql . = " and xxx2 ";
}
if(条件3){
$sql . = " and xxx3 ";
}
sql语句优化 遵循explain
不同的条件调用不同的语句就可以了。
不同的条件调用不同的语句就可以了。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号