Sql語句中IN等方面的用法

來源:互聯網
上載者:User
導讀:
select * from txt1
select * from txt2
select * from txt1 where name in (select name from txt2 where chk = 0)
select * from txt1 where name not in (select name from txt2 where chk = 0)
select * from txt1 inner join txt2 on txt1.name = txt2.name
select * from txt1 left join txt2 on txt1.name = txt2.name
select * from txt1 right join txt2 on txt1.name = txt2.name
select * from txt1,txt2 where txt1.name = txt2.name Order By txt2.ID Desc
select Txt1.name,Sum(Txt1.Sumint) from txt1,txt2 where txt1.name =txt2.name Group by txt1.name
select count(Txt1.name),sum(sumint) from txt1,txt2 where txt1.name =txt2.name having sum(sumint)<10
select count(Txt1.name),sum(sumint) from txt1,txt2 where txt1.name =txt2.name having Sum(sumint) >50
select * from txt1,txt2 where txt1.name <>txt2.name Order by Txt1.Name compute Sum(sumint) by txt1.name
insert into txt3 select name,Sumint from txt1
In:等值串連,用來尋找多表相同欄位的記錄
Not In:非等值串連,用來尋找不存在的記錄
Inner join:內串連,主要用來尋找都合格記錄
Left join:左串連,主要用來尋找左邊有,右邊沒有的用空值表達
Right join:右串連,主要用來尋找右邊有,左邊沒有的用空值表達
Order By:升序 Asc 降序 Desc
Group By:分組排序 按欄位分組(如按班級分),使用的都要有集合函數存在
Having :對分組條件進行判斷,使用都要確保每個欄位都要用集合函數
COMPUTE BY:子句使您得以用同一 SELECT 語句既查看明細行,又查看合計列。可以計運算元組的匯總值,也可以計算整個結果集的匯總值。
資料列彙總函式名稱;例如,SUM、AVG、MIN、MAX 或 COUNT
insert into:主要把查詢的語句插入到新表。
txt1表的資料
ID Name SumInt
1 張三 55
2 李四 85
3 王五 85
4 趙六 855
txt2表的資料
ID Name Chk
1 張三 0
2 李四1 1
3 王五 0
4 趙六 0

本文轉自
http://hi.baidu.com/qzrc/blog/item/ff7ad688bc548394a4c272ce.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.