結果刪除重複我具有低於使用MySQL和PHP
SELECT A.order_no, A.order_date,
COUNT(B.reaction_no) as tot_reaction_no,
SUM(CASE
WHEN (B.purification != '') THEN 1
ELSE 0
END) as tot_purification
FROM order_header A
LEFT JOIN order_reactions B ON A.order_no = B.order_no
WHERE A.order_date BETWEEN '2015-10-01 00:00:00' AND '2016-09-01 00:00:00'
AND A.order_no = '23746'
GROUP BY A.order_no
一個查詢給定的,這將結果示於圖片。但結果是錯誤的,因爲一些條目是重複的。所以我必須刪除重複並打印計數。計數需要的是「列」的計數從表1
也許您可以在查詢中使用distinct關鍵字 – DBX12
[MySQL:僅選擇列中的唯一值](http:// stackoverflow。 com/questions/8571902/mysql-select-only-unique-values-from-a-column) –
當我使用DISTINCT –