0

クエリを実行する理由

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-グループ関数の使用が無効です

MySQL5.0.51ではなくMySQL4.0.24で?

4

1 に答える 1

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
于 2010-04-19T06:24:47.750 に答える