zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    【leetcode】1030. Matrix Cells in Distance Order
    【leetcode】1031. Maximum Sum of Two Non-Overlapping Subarrays
    【leetcode】1032. Stream of Characters
    L120 单词造句
    L119
    L118
    2018.8.6邮件规范一
    L117
    L116
    L115
  • 原文地址:https://www.cnblogs.com/liangyy/p/10025377.html
Copyright © 2011-2022 走看看