andmspy
V2EX  ›  数据库

sqlite3 函数嵌套疑问

  •  
  •   andmspy · Feb 22, 2018 · 2243 views
    This topic created in 3197 days ago, the information mentioned may be changed or developed.

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

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

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

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

    4 replies  •  2018-03-06 23:19:15 +08:00
    Dic4000
    Dic4000
    Feb 22, 2018
    1
    试试:select date from worker where date=Date('now')
    alpenstock
    alpenstock
    Feb 23, 2018
    2
    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
    alpenstock
    Feb 23, 2018
    3
    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
    andmspy
    OP
    Mar 6, 2018
    4
    谢谢,谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4482 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:39 · PVG 14:39 · LAX 22:39 · JFK 01:39
    ♥ Do have faith in what you're doing.