› 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
shaweren
V2EX  ›  MySQL

MYSQL 根据年月如何查询数据?

  •  
  •   shaweren · Dec 2, 2019 · 7222 views
    This topic created in 2495 days ago, the information mentioned may be changed or developed.

    数据库字段 time=2019-09-09 根据 year =2019,month=9 如何查询 2019 年 9 月的数据呢?

    13 replies  •  2019-12-03 09:52:22 +08:00
    finaldusk
        1
    finaldusk  
       Dec 2, 2019
    time>=2019-09-01 and time<2019-10-01
    arthas2234
        2
    arthas2234  
       Dec 2, 2019
    date_format(time, '%Y%m') = '201909'
    changdy
        3
    changdy  
       Dec 2, 2019
    @arthas2234 2333 这样查询 不怕数据库崩溃吗...
    qiayue
        4
    qiayue  
       Dec 2, 2019
    1 楼 2 楼都可以实现,但是如果数据量大,建议用 1 楼方法。
    甚至可以改表,增加 year,month 字段
    Orenoid
        5
    Orenoid  
       Dec 2, 2019
    不是有 year 和 month 函数吗
    arthas2234
        6
    arthas2234  
       Dec 2, 2019   ❤️ 1
    @changdy 楼主没说数据量有多大,但是问这个问题,默认是做作业了
    chickenJuicer
        7
    chickenJuicer  
       Dec 2, 2019
    要不你直接 like 吧...
    changdy
        8
    changdy  
       Dec 2, 2019
    @arthas2234 哈哈 有那么一丢丢不太合适


    @qiayue 应该用虚拟列 这种场景简直量身定做
    shaweren
        9
    shaweren  
    OP
       Dec 2, 2019
    感谢各位大佬 /
    <BR>
    month(stime)='$month' AND year(stime)='$year' <br>解决办法
    aapon
        10
    aapon  
       Dec 2, 2019 via iPhone
    areless
        11
    areless  
       Dec 2, 2019 via Android
    unix 时间戳不好用吗。。。
    ackoly
        12
    ackoly  
       Dec 2, 2019 via iPhone
    @shaweren 一楼的方法,如果数据量大点,秒杀你这种写法
    ganning
        13
    ganning  
       Dec 3, 2019
    更倾向于 1 楼的方法。最简单的往往是最高效的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 17:39 · PVG 01:39 · LAX 10:39 · JFK 13:39
    ♥ Do have faith in what you're doing.