如何在这个cquery中使用group by?

时间:2014-04-28 16:47:10

标签: mysql sql

我想知道每个sku中有多少unspsc个。有人可以帮忙吗?

SELECT eav.value AS 'unspsc', e.sku
FROM catalog_product_entity e
JOIN catalog_product_entity_varchar eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE ea.attribute_code = 'unspsccode'

1 个答案:

答案 0 :(得分:0)

SELECT eav.value AS 'unspsc',COUNT( e.sku)
FROM catalog_product_entity e
JOIN catalog_product_entity_varchar eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE ea.attribute_code = 'unspsccode'
GROUP BY eav.value