代码之家  ›  专栏  ›  技术社区  ›  Kamil Szot

在mysql 4中使用group函数无效(不在5中)

  •  0
  • Kamil Szot  · 技术社区  · 14 年前

    知道为什么要问吗

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

    1 回复  |  直到 13 年前
        1
  •  1
  •   Kamil Szot    14 年前

    自我反应。提到我要在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