我有MySQL数据库专栏的内容:
+-------+
|Status |
+-------+
| | // empty
| | // empty
|Reject |
|reject |
+-------+
我对此Status
有一些条件,因此用户可以看到此案例的判断:
Reject
(自动,如果选择项目)或reject
(某些用户在编辑数据后输入此内容)echo Reject empty
或'接受'或'接受'回应接受我试过这个:
if($row['Status'] == "Reject"){
echo "Reject";
}
elseif($row['Status'] == "reject"){
echo "Reject";
}
else{
echo "Accept";
}
但是,它总是回应Accept
。导致下面的查询结果为empty
:
SELECT COUNT(Serial_number) AS n, SUM(S) AS S,SUM(A) AS A, SUM(B) AS B, SUM(C) AS C,
ROUND((((SUM(S)*1)+(SUM(A)*1)+(SUM(B)*0.4)+(SUM(C)*0.1))/COUNT(Serial_number)*1000000),0) AS PPM,
Status
FROM inspection_report WHERE Model LIKE 'MDV-Z700D' AND Lot_no LIKE '010A'
AND Line LIKE 'FA 21' AND Range_sampling ='177X0001-177X0100' GROUP BY Range_sampling
结果:
n S A B C PPM Status
20 0 1 0 0 50000 //this empty status make echo = Accept
如果使用GROUP_CONCAT(Status)
结果为,,Reject,reject
。那么,如何回应每个条件参考上述2个案例?
注意:我想如果在该列内部有拒绝值,结果回声拒绝,即使我有很多接受值。
答案 0 :(得分:2)
<击> 撞击>
<击>如果Status
为NULL
,您可以使用COALESCE
GROUP_CONCAT(COALESCE(Status,'Accept'))
击> <击> 撞击>
但如果它是空字符串''
,请使用inline IF statement
GROUP_CONCAT(if(Status = '' or Status = 'accept', 'Accept', Status))
<强>更新强>
IF(LOCATE('Reject',GROUP_CONCAT(DISTINCT if(Status = '' or Status = 'accept', 'Accept', Status))) > 0, 'REJECT', 'ACCEPT')