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=#
  • 相关阅读:
    python之面向对象编程
    python的模块引用和查找路径
    python的迭代器、生成器、三元运算、列表解析、生成器表达式
    python文件操作
    lesson4-图像分类-小象cv
    lesson3-神经序列模型I-小象
    fast ai环境配置
    YOLO
    lesson2-cnn-fastai
    mask-code-python
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13599708.html
Copyright © 2011-2022 走看看