gpt4 book ai didi

mysql - MySQL 4 中组函数的无效使用(5 中没有)

转载 作者:行者123 更新时间:2023-11-29 15:03:25 25 4
gpt4 key购买 nike

知道为什么查询

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 上?

最佳答案

self 回应。在 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

关于mysql - MySQL 4 中组函数的无效使用(5 中没有),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2665461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com