白嫖大家的代码, Mysql 如何按月份调用,或是如何设计数据库... - V2EX
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
enzo1205
V2EX    MySQL

白嫖大家的代码, Mysql 如何按月份调用,或是如何设计数据库...

  •  
  •   enzo1205 Mar 4, 2022 1756 views
    This topic created in 1535 days ago, the information mentioned may be changed or developed.

    最终的效果是要这样,以此类推

    . . 2022 1 月 2 月 3 月 4 月 5 月 6 月 7 月 8 月 9 月 10 月 11 月 12 月 . . .

    博客只有一个时间字段..我现在可以调出来,系统里面有的文章.. 比如 2022 1 月 2 月 3 月... 但是我想弄完整的月份,有文章话,该月份可以点击,没有文章的月份不能点击... 麻烦大家给个思路.... 谢谢

    mineralsalt
        1
    mineralsalt  
       Mar 4, 2022
    按月统计记录数量

    SELECT
    from_unixtime( create_time, "%Y-%m" ) AS months,
    count( id ) AS counts
    FROM
    `table`
    GROUP BY
    months;
    KotlinAmai
        2
    KotlinAmai  
       Mar 4, 2022
    select concat('2022', '-', months.month) as time, count(articles.id) > 0 as exist
    from (
    select '01' as month
    union
    select '02' as month
    union
    select '03' as month
    union
    select '04' as month
    union
    select '04' as month
    union
    select '06' as month
    union
    select '07' as month
    union
    select '08' as month
    union
    select '09' as month
    union
    select '10' as month
    union
    select '11' as month
    union
    select '12' as month
    ) as months
    left join articles on month(created_at) = months.month and year(articles.created_at) = '2022'
    group by time;


    随便写的,不保证任何效率
    rabbbit
        3
    rabbbit  
       Mar 4, 2022
    CREATE TABLE IF NOT EXISTS `blog` (
    `id` int NOT NULL DEFAULT '0',
    `title` varchar(100) NOT NULL DEFAULT '',
    `createTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `content` mediumblob
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

    SELECT from_unixtime(UNIX_TIMESTAMP(createTime), '%Y 年%m 月') TIME FROM blog GROUP BY time

    SELECT
    *,
    from_unixtime(UNIX_TIMESTAMP(createTime), '%Y 年%m 月') TIME,
    ROW_NUMBER() over (partition by from_unixtime(UNIX_TIMESTAMP(createTime), '%Y-%m') ORDER BY createTime) num
    FROM blog
    About     Help     Advertise     Blog     API     FAQ     Solana     905 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 39ms UTC 22:33 PVG 06:33 LAX 15:33 JFK 18:33
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86