我需要帶'other'的var_name列在最後,所以我試過了。它的工作原理,但我需要由perc命令第一個選擇語句,UNION不會讓我。無論如何,我確定使用UNION可能是錯誤的。Mysql按例外排序
SELECT count(*) as cnt,(count(*)/$cty)*100 AS perc, var_name
FROM tbl_answers
WHERE int_question = $id_question AND var_response <> ''
AND var_name <> 'comments' AND var_name <> 'Other'
GROUP BY var_name
UNION
SELECT count(*) AS cnt,(count(*)/$cty)*100 as perc,var_name
FROM tbl_answers
WHERE int_question = $id_question
AND var_response <> '' AND var_name <> 'comments' AND var_name = 'Other'
GROUP BY var_name
感謝例子和解釋 – user1083382