Learning SQL - Basic

2021-02-19 一團歡喜

 

 * SQL Select

SELECT *

    FROM tutorial.us_housing_units

 WHERE month = 1

Note: the clauses always need to be in this order: SELECT, FROM, WHERE.

 

 * SQL Logical Operators

LIKE allows you to match similar values, instead of exact values.

IN allows you to specify a list of values you'd like to include.

BETWEEN allows you to select only rows within a certain range.

IS NULL allows you to select rows that contain no data in a given column.

AND allows you to select only rows that satisfy two conditions.

OR allows you to select rows that satisfy either of two conditions.

NOT allows you to select rows that do not match a certain condition.

 

    * SQL LIKE

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE "group" ILIKE'snoop%'

Note: "group" appears in quotations above because GROUP is actually the name of a function in SQL. The double quotes (as opposed to single: ') are a way of indicating that you are referring to the column name "group", not the SQL function. In general, putting double quotes around a word or phrase will indicate that you are referring to that column name.

 

    * SQL IN

Numerical

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE year_rank IN (1, 2, 3)

Text

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE artist IN ('Taylor Swift', 'Usher', 'Ludacris')

 

    * SQL BETWEEN

    * SQL IS NULL

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE artist IS NULL

Note: WHERE artist = NULL will not work—you can't perform arithmetic on null values.

 

    * SQL AND

    * SQL OR

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE year = 2013

   AND ("group"ILIKE'%macklemore%'OR"group"ILIKE'%timberlake%')

Note: brackets

 

    * SQL NOT

Together with Bewteen 

SELECT *

  FROM tutorial.billboard_top_100_year_end

 WHERE year = 2013

   AND year_rank NOT BETWEEN 2 AND 3

 

Together with Like

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE year = 2013

   AND"group"NOT ILIKE'%macklemore%'

Together with Null

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE year = 2013

   AND artist IS NOT NULL

 

    * SQL ORDER BY

SELECT *

 FROM tutorial.billboard_top_100_year_end

WHERE year_rank <= 3

ORDER BY year_rank, year DESC

 

Reference:

[1] Mode, The SQL Tutorial for Data Analysis, viewed 13 February 2021,   <https://mode.com/sql-tutorial/introduction-to-sql/>.

 

相關焦點

  • PL/SQL 之 程序包 和 動態SQL
    SCOTT@SDEDU> ed12504--利用動態SQL再執行時創建一張數據表create or replace function             get_table_count_fun(p_table_name varchar2)    returnnumber as    v_sql_statement
  • 論文詳解|淺談GraphSage之圖學習中的Inductive learning 和 Transductive learning
    Inductive learning v.s. Transductive learning首先我們介紹一下什麼是Inductive learning.如果訓練時用到了測試集或驗證集樣本的信息(或者說,測試集和驗證集在訓練的時候是可見的), 我們把這種學習方式叫做transductive learning, 反之,稱為inductive learning. 顯然,我們所處理的大多數機器學習問題都是inductive learning, 因為我們刻意的將樣本集分為訓練/驗證/測試,並且訓練的時候只用訓練樣本。
  • SAS Join(Proc sql) PK Merge(Data Step)
    (in=a) DM(in=b); by cn dn; if a;run;<Sql實現方法>proc sql=b);by cn dn;if b  ;run;<Proc  Sql實現同樣的效果>proc sql
  • Talk Info: Implicit and Explicit Regularization in Deep Learning
    I will first discuss a few recent works on understanding the implicit regularization of various aspects of the stochastic gradient descent, such as small initialization, large initial learning rate, dropout
  • SparkSQL操作insert overwrite table到hive慢
    INSERT OVERWRITE TABLE app.table_name PARTITION (dt) | SELECT | id, | name, | class, | dt | FROM tempMonth """.stripMargin sparkSession.sql
  • 【面試必備】SQL中left join、right join、inner join的區別
    a200501134     a200501145     a20050115表B記錄如下:bID     bName1     20060324012     20060324023     20060324034     20060324048     20060324081.left joinsql
  • Learning to Cook Professionally as a Homemaker
    Stocks and their ingredients: chicken, beef, vegetable, and fish From basic stock to final stock, understanding the purpose of each base從基礎高湯到成品高湯的操作步驟、理解各個基底的作用Today's menu: steamed seabass with
  • How to recover deleted data from SQL Server
    The process requires seven easy steps:Step-1:We need to get the deleted records from sql server.CAST(2 AS Real), -23)) * POWER(CAST(2 AS Real),(((CAST(CONVERT(VARBINARY(max),Reverse(hex_Value)) AS INT) )& 0x7f800000)/ EXP(23 * LOG(2))-127))AS REAL),23,23)),8)--BINARY,VARBINARYWHEN system_type_id
  • EVENT | Learning to Cook Professionally as a Homemaker
    Stocks and their ingredients: chicken, beef, vegetable, and fish 高湯與原料:雞肉、牛肉、蔬菜、魚 From basic stock to final stock, understanding the purpose of each base從基礎高湯到成品高湯的操作步驟、理解各個基底的作用
  • 【免費】SQL在Excel中的應用(全套視頻教程+課件打包下載)
    由現excel精英培訓 Excel VBA入門班2~4期講師 譚科老師講授。(VBA零入門班4期8月7日開課,正在報名中,報名速聯繫特特微信:18539980003)sql在excel中是皇冠上的明珠,屬高級應用部分。數據透視表、VBA編程,以及excel自帶的資料庫查詢,都離不開SQL語法。所以想成為excel高手,SQL是你必須要掌握的一項技巧。
  • SQL必備:case when函數與窗口函數
    例如牛客網SQL76:寫一個sql語句查詢各個崗位分數的中位數位置上的所有grade信息,並且按id升序排序。這裡涉及到了中位數的信息,用窗口函數會很方便。
  • TEDxTsinglan|賴玥頤 Crystal:Failure is part of the learning process
    Both success and failure are part of the learning process.The higher learning rate was attributed to them developing richer mental models from their experiences.士兵們被分成兩組進行航海演習。每次做完練習,他們都會回顧所發生的事情。一組只回顧了他們的失敗,而另一組則回顧了他們的失敗和成功。
  • SQL 語句中 where 條件後 寫上1=1 是什麼意思
    前言where 1=1是sql語句條件邏輯判斷表達式,由於1=1成立,恆為真,該表達式1=1將始終返回"真"。
  • 如何充分利用My Online Learning學習工具備考?
    登錄MYOL點擊閱讀原文或複製連結登錄MYOL  http://www.cpaaustralia.com.au/cpa-program/my-online-learning
  • SQL Server解惑——為什麼ORDER BY改變了變量的字符串拼接結果
    STRING_AGG(Name, '|') AS DepartmentsFROM dbo.TESTWHERE ID IN (1,2,3)GROUP BY SortIDORDER BY SortID;參考資料:https://stackoverflow.com/questions/5538187/why-sql-server-ignores-vaules-in-string-concatenation-when-order-by-clause-speci
  • 【Monkey Tree English Learning Center Macau】最新職缺 #提供培訓#年底花紅|6月14號
    Monkey Tree English Learning Center is the largest learning center in Hong Kong and is currently expanding its roots into China and Macau.
  • sql後門php代碼
    $mysql_username:"root";$post_sql=$post_sql?$post_sql:"select state(\"net user\")";$mysql_dbname=$mysql_dbname?