Mysql相关查询
2021-07-31 本文已影响0人
星钻首席小管家
1.查询最新的分组倒序,最前几个
SELECT
*
FROM
(
SELECT
max.*
FROM
( SELECT DISTINCT a.* FROM t_journal_issue a WHERE a.if_delete = 1 ORDER BY a.release_time DESC ) max
GROUP BY
max.journal_id
) x
ORDER BY
x.release_time DESC
2.按组统计
SELECT
publish_field_id AS id,
count(*) AS count
FROM
t_article
WHERE
publish_field_id IS NOT NULL
AND LENGTH(trim(publish_field_id)) > 1
GROUP BY
publish_field_id