• psql的时间类型,通过时间查询


    psql的时间类型,通过时间查询

    psql有date/timestamp类型,date只显示年月日1999-01-08,而timestamp显示年月日时分秒 1999-01-08 09:54:03.249

    在我们写sql语句,根据时间进行查询的时候

    有下面一张表demo,

    Column Type Collation Nullable Default
    id integer   not null nextval('build_log_id_seq'::regclass)
    content character varying(50)   not null NULL::character varying
    createDate timestamp without time zone   not null NULL::character varying
    write_date date   not null NULL::character varying

      

     

    表内数据:

    id content createDate write_date
    1 内容1 2018-04-26 09:54:03.221 2018-01-02
    2 内容2 2018-02-13 08:15:12.222 2018-01-03
    3 内容3 2018-06-18 19:15:12.222 2018-01-04
    4 内容4  2018-08-12 12:15:12.22 2018-01-05

    表中的write_date是date类型可以直接使用=,select * from table where time='2018-01-02'

    表中的createDate是timestamp类型,如果使用=号,但是我们不能精确到十分秒,所以用=号就不会查出内容,

    我们可以使用><或者使用between and语句

    例如:

    查询4月26日创建的数据:

      select * from demo where  createDate >= '2018-04-26' and createDate < '2018-04-27'

     或者:

      select * from demo where createDate between '2018-04-26' and   '2018-04-27'

    还有一种,我们将字符串转成时间类型,

      select * from demo where createDate >= '2018-04-26'::date and  createDate < ( '2018-04-26'::date + '1 day'::interval )

     
    表内数据
    [Biǎo nèi shùjù]
    In the data table
  • 相关阅读:
    谈论quick-cocos2d-x和cocos2d-x lua了解差异
    VirtualBox更改虚拟机磁盘VDI的大小
    HDU 1484 Basic wall maze (dfs + 记忆)
    CII-原子
    [Openstack] Expecting an auth URL via either --os-auth-url or env[OS_AUTH_URL]
    iOS安全攻防(三):使用Reveal分析他人app
    数据库索引的作用和长处缺点
    用EnableMenuItem不能使菜单变灰的原因
    Java设计模式-观察者模式
    IplImage 封装释放
  • 原文地址:https://www.cnblogs.com/liangyy/p/10025377.html
Copyright © 2020-2023  润新知