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=#
  • 相关阅读:
    Java设计模式の工厂模式
    写Java代码分别使堆溢出,栈溢出
    Java7/8 中的 HashMap 和 ConcurrentHashMap 全解析
    Java集合---ConcurrentHashMap原理分析
    Java 集合类详解
    HashMap详谈以及实现原理
    Java设计模式の代理模式
    Java设计模式の单例模式
    mysql之 navicat表权限设置
    MySQL之You can't specify target table for update in FROM clause解决办法
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13599708.html
Copyright © 2011-2022 走看看