我有一個問題,我的查詢和mysql引發以下錯誤:MySQL的錯誤:SELECT列表是不是在GROUP BY子句
#1055 - Expression #66 of SELECT list is not in GROUP BY clause and contains nonaggregated column 's.status' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
查詢:
select p.*,
pd.*,
m.*,
IF(s.status, s.specials_new_products_price, null) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
FROM products p
LEFT JOIN specials s ON p.products_id = s.products_id
LEFT JOIN manufacturers m using(manufacturers_id) ,
products_description pd,
categories c,
products_to_categories p2c
WHERE p.products_view = 1
AND p.products_status = 1
AND p.products_archive = 0
AND c.virtual_categories = 0
AND p.products_id = pd.products_id
AND p.products_id = p2c.products_id
AND p2c.categories_id = c.categories_id
AND pd.language_id = 1
GROUP BY p.products_id;
打我吧!很好的解釋。 –
我試過不同的方式,像選擇SQL_CALC_FOUND_ROWS s.products_id,或選擇SQL_CALC_FOUND_ROWS計數(p.products_id),但沒有解決方案任何想法重寫這個? – kurama
@ kurama您正在嘗試彙總您正在分組的列。正如Bill所描述的那樣,您需要確保選擇列表中包含的其他列包含「GROUP BY」子句,或者它們已經彙總,或者依賴於分組列,以便分組正常工作。例如,從產品p組中選擇p.products_id,s.status,sum(p.products_price),... p.products_id,s.status' –