美文网首页
Mysql相关查询

Mysql相关查询

作者: 星钻首席小管家 | 来源:发表于2021-07-31 16:53 被阅读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
    

    相关文章

      网友评论

          本文标题:Mysql相关查询

          本文链接:https://www.haomeiwen.com/subject/ysicyltx.html