0

I have this content of my MySQL database column:

+-------+
|Status |
+-------+
|       | // empty
|       | // empty
|Reject |
|reject |
+-------+

I have some condition for this Status, so the user can see the judgement of this case:

  1. If result Reject(automatically if select item) or reject(some users type this after edit data ) echo Reject
  2. If result empty or 'Accept' or 'accept` echo Accept

I have try this :

if($row['Status'] == "Reject"){
                echo "Reject";
                }
        elseif($row['Status'] == "reject"){
                echo "Reject";
                }
        else{
                echo "Accept";
                }

But, it's always echoing Accept. Cause the result of the query below is 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

Result :

n   S   A   B   C   PPM    Status
20  0   1   0   0   50000             //this empty status make echo = Accept

If using GROUP_CONCAT(Status) result is ,,Reject,reject.So, how to echo each condition refer to 2 case above ?


Note : I want if inside that column have reject value the result echo reject even I have a lot of accept value.

4

1 に答える 1

2

の場合StatusNULL、使用できます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')
于 2012-12-25T02:37:52.983 に答える