【问题标题】:Invalid use of group function in MySQL 4 (not in 5)MySQL 4 中组函数的无效使用(不在 5 中)
【发布时间】:2010-04-19 06:13:43
【问题描述】:

知道为什么要查询

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 - 组函数使用无效

在 MySQL 4.0.24 上而不是在 MySQL 5.0.51 上?

【问题讨论】:

  • 制造商表是否只有两列,id + 1 other?

标签: mysql mysql-error-1111


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 2014-03-29
    • 1970-01-01
    相关资源
    最近更新 更多