2010-04-19 58 views
0

任何想法,爲什麼查詢無效在MySQL中使用4組功能(不是在5)

SELECT 
    m.* 
FROM 
    products_description pd, 
    products p 
    left join manufacturers m on p.manufacturers_id = m.manufacturers_id, 
    products_to_categories p2c 
WHERE 
    p.products_carrot = '0' and 
    p.products_status = '1' and 
    p.products_id = p2c.products_id and 
    pd.products_id = p2c.products_id and 
    pd.language_id = '4' and 
    p2c.categories_id = '42' 
GROUP BY manufacturers_id 
ORDER BY COUNT(*) 

可能給下列錯誤:

#1111 - Invalid use of group function

MySQL的4.0.24,而不是在MySQL 5.0。 51?

+0

製造商表只有兩列,id + 1其他嗎? – 2010-04-19 06:17:00

回答

1

自我反應。提到一列,我想通過SELECT子句進行排序,並使用別名進行排序:

SELECT 
    m.*, COUNT(*) as cnt 
FROM 
    products_description pd, 
    products p 
    left outer join manufacturers m on p.manufacturers_id = m.manufacturers_id, 
    products_to_categories p2c 
WHERE 
    p.products_carrot = '0' and 
    p.products_status = '1' and 
    p.products_id = p2c.products_id and 
    pd.products_id = p2c.products_id and 
    pd.language_id = '4' and 
    p2c.categories_id = '42' 
GROUP BY p.manufacturers_id 
ORDER BY cnt 
+0

謝謝,這也解決了我的問題:) – 2011-04-04 17:08:23