有4种接收方式。 1) 送货 2) 提货 3) mobile_topup 4) 银行_存款
如果有 2 个移动充值,我只需要一个。但是,如果有两种交付方式,那么我都需要它们。为了实现这一点,我创建了这个查询:
$clause = "SELECT id FROM beneficiary_payment_info
GROUP BY IF(ben_payment_method='mobile_topup', '', ben_payment_method)";
但是,问题是,它也是通过传递方法进行分组的。我不想要这样。
现在,我的数据库中有 2 mobile_topup
、2 Delivery
和 银行存款
。
我需要 1 mobile_topup
、2 次送货
和 1 笔银行存款
。
我只是想知道这个查询是否可能,或者我需要在 php
中执行它?
编辑
临时,在php
中我有这个解决方案。但是,看起来不太可靠。
$mobile_count = array();
for($i=0; $i<count($data); $i++){
if($data[$i]['ben_payment_method']=='mobile_topup'){
//unset($data[$i]);
array_push($mobile_count, $i);
}
}
if(count($mobile_count) > 1){
for($i=0; $i<count($mobile_count)-1; $i++){
unset($data[$mobile_count[$i]]);
}
}
最佳答案
$clause = "SELECT id FROM beneficiary_payment_info
GROUP BY IF(ben_payment_method='mobile_topup', ben_payment_method, id,)";
关于php - mysql根据特定条件和列值进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27949979/