V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
andmspy
V2EX  ›  数据库

sqlite3 函数嵌套疑问

  •  
  •   andmspy · 2018-02-22 17:25:14 +08:00 · 909 次点击
    这是一个创建于 2226 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请教一下,想每次批量处理提取的数据都是当前日期的数据,可以就是不能提取出来,也没有报错,就是不知道为什么

    select date from worker where date=(select date('now'))

    背景: 表:worker 字段:date 格式:2018/2/22

    但是如果修改成 select date from worker where date=‘ 2018/2/22 ’ 这样就可以成功提取出来,用函数就不行了。

    4 条回复    2018-03-06 23:19:15 +08:00
    Dic4000
        1
    Dic4000  
       2018-02-22 18:16:54 +08:00
    试试:select date from worker where date=Date('now')
    alpenstock
        2
    alpenstock  
       2018-02-23 09:48:58 +08:00
    sqlite date() 函数默认的格式是 2018-02-22,不是 2018/2/22
    可以用
    select date from worker where date=(select strftime('%Y/%m/%d','now'));
    或者
    select date from worker where date= strftime('%Y/%m/%d','now');
    alpenstock
        3
    alpenstock  
       2018-02-23 09:52:31 +08:00
    SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

    TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
    REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
    INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

    参考自 http://sqlite.org/datatype3.html
    andmspy
        4
    andmspy  
    OP
       2018-03-06 23:19:15 +08:00
    谢谢,谢谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5688 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:46 · PVG 09:46 · LAX 18:46 · JFK 21:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.