supplier:供应商dealer:经销商
select * from table
where
if(supplier!=0){ //当供应商不为0时,goods_id使用供应商的goods_id
goods_id=supplier_goods
}
else(dealer!=0){ //当经销商不为0时,goods_id使用经销商的goods_id
goods_id=dealer_goods
}
可以有这种写法吗? tp中又该怎么写?
7 回答
烙印99
TA贡献1829条经验 获得超13个赞
//大概这样,只是个大概:
if($supplier !==0 ){ //当供应商不为0时,goods_id使用供应商的goods_id
$where = 'goods_id=supplier_goods';
}else($dealer !== 0){ //当经销商不为0时,goods_id使用经销商的goods_id
$where = 'goods_id=dealer_goods';
}
$data = $mysql->query("select * from table where {$where}");
建议将判断逻辑放在前面,让SQL一目了然
森栏
TA贡献1810条经验 获得超5个赞
$where['goods_id'] = ($supplier != 0) ? $supplier_goods : $dealer_goods;
Db::table('table')->where($where)->select();
- 7 回答
- 0 关注
- 951 浏览
添加回答
举报
0/150
提交
取消