需求:取cover_percent 按从大到小取值,且每组category_id 只取一行记录
如下sql 含义:cover_percent 取最大的,且category_id 是去重的,每组category_id 只取一行记录
SELECT
id,
tag_name,
fact_column_show,
fact_column_type,
category_id,cover_percent
FROM tag_info a
where
bisType = 0
AND tag_type IN (1, 2, 7)
and fact_column_show is not null
and fact_column_type is not null
AND NOT EXISTS (
SELECT
1
FROM
tag_info b
WHERE
a.category_id = b.category_id
AND b.cover_percent > a.cover_percent
)
ORDER BY cover_percent DESC
LIMIT 0, 8