-1
我有兩個表這樣顯示GROUP_CONCAT空記錄
profile_answers
+---------+------------+
| id | class_name |
+---------+------------+
| 1 | Class 1 |
| 2 | Class 2 |
| 3 | Class 1 |
+---------+------------+
的教育
+---------+--------------------+------------+
| id | profile_answers_id | sample |
+---------+--------------------+------------+
| 1 | 1 | 1234 |
| 2 | 1 | 2334 |
| 3 | 1 | 3434 |
+---------+------------+--------------------+
我跑的查詢,
select educations.profile_answer_id, GROUP_CONCAT(educations.sample) from educations
LEFT JOIN profile_answers ON educations.profile_answers_id = profile_answers.id
我
+--------+--------------------+-------------+
| id | sample |
+---------+--------------------+------------+
| 1 | 1234,2334,3434 |
+---------+------------+--------------------+
其實我是想,
+--------+--------------------+-------------+
| id | sample |
+---------+--------------------+------------+
| 1 | 1234,2334,3434 |
| 2 | NULL |
| 3 | NULL |
+---------+------------+--------------------+
我試過了,ISNULL,IFNULL與group_by profile_answers.id
這給了我正確的結果組合,但它竟然是相當昂貴運行時間條款
給出給出正確結果的昂貴查詢? – Dukeling 2013-02-11 20:35:35
你剛纔問這個問題... – sgeddes 2013-02-11 20:36:46
http://dpaste.com/919899/ ..在這個查詢上花費了15秒 – 2013-02-11 20:40:15