group by 用法:
官方的解释:select 后面的字段必须出现在 group by 后面, 除非是聚合,sum,或者count
但是如果 是多表联查, SELECT
c.`name` AS NAME,
sum(b.uv) AS
VALUE
FROM
meta.dic_project_category a,
rpt_program_cat_people b,
meta.dic_app_category c
WHERE
a.id = b.`name`
AND a.id > 1
AND b.tag_name = ‘app_prefer1‘
AND c.id = b.tag_value
GROUP BY
b.tag_value
ORDER BY
b.uv DESC
LIMIT 10
这个例子。 group by 的是 B表的tag_value, 但是B表这个字段和C表的name,是一 一对应的,所以也可以 。
时间: 2024-10-13 04:19:07