zoukankan      html  css  js  c++  java
  • [Postgres] Conditionally Select out Filtered Data with SQL Where

    SQL gives us the power to choose what data we pull out of our table. We will use the where clause within our select statement with many operators. These include the greater than, less than, equal, and not equal. We will also use some special operators such as "in", "between", and "is".

    not equal:

    $ postgres=# select * from Users where create_date <> '2018-05-05';

    is:

    $ postgres=# select * from Users where first_name is null;
      create_date |             user_handle              | last_name | first _name
    --------------+--------------------------------------+-----------+-------------
      2018-08-06  | fw1kv3z4-fk98-pl2f-se48-f823jfhaj39f |           |
      (1 row )

    If you use =

    $ postgres=# select * from Users where first_name = null;
      create_date |             user_handle              | last_name | first _name
    --------------+--------------------------------------+-----------+-------------
      (0 rows )
    $ postgres=#

    between:

    $ postgres=# select * from Users where create_date between '2018-05-01' and '2018-07-01';
      create_date |             user_handle              | last_name | first _name
    --------------+--------------------------------------+-----------+-------------
      2018-06-06  | 2839f831-f82c-faj3-aof3-fj28ddks39ek | clark     | tyler
      2018-06-06  | 6ab3b2d2-8e02-890c-bb6d-61a67cd43f31 | jones     | debbie
      (2 rows )
    $ postgres=#

    in:

    $ postgres=# select * from Users where last_name in ('clark', 'jones');
      create_date |             user_handle              | last_name | first _name
    --------------+--------------------------------------+-----------+-------------
      2018-06-06  | 2839f831-f82c-faj3-aof3-fj28ddks39ek | clark     | tyler
      2018-06-06  | 6ab3b2d2-8e02-890c-bb6d-61a67cd43f31 | jones     | debbie
      (2 rows )
    $ postgres=#
  • 相关阅读:
    CAP概述与技术选型
    maven基础命令
    那就从头开始吧,哈哈。
    react 小细节
    二分查找法,折半查找原理
    心态很重要
    apache 软件基金会分发目录。
    jquery的基础知识复习()
    jquery的基础知识复习(基础选择器,属性选择器,层级选择器)
    CPP函数类型转换
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13599708.html
Copyright © 2011-2022 走看看