執行sql: mysql
SELECT ability,count
FROM
(
SELECT
q.ability,
count( 1 ) as count
FROM
spk_wrong_que_train t
LEFT JOIN spk_hsk_question q ON t.question_id = q.id
WHERE
t.user_id = 1
group by
q.ability
UNION
SELECT '1' as ability,'0' as count
union
SELECT '3' as ability,'0' as count
union
SELECT '4' as ability,'0' as count
union
SELECT '5' as ability,'0' as count
union
SELECT '6' as ability,'0' as countsql
) B
GROUP BY B.abilitythis
結果:執行成功spa
5.7以上版本 結果:報錯blog
問題:it
報錯信息: 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'B.count' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_byio
因爲本地環境mysql 是5.7如下版本,線上5.7以上版本:function
解決:class
使用ANY_VALUE(),MySQL會忽略每一個名稱組中的地址值的不肯定性並接受查詢,就能夠了!nio