oracle資料庫之SQL結構化查詢語言 (SQL)

來源:互聯網
上載者:User

標籤:max   font   重複   rac   class   blog   不同   st表   右外串連   

1.select

select * from test                 //查詢test裡的所有列的資訊select test1,2,3 from test         //查詢test表中的test1,2,3列中的資料

1.1 分組和排序

select * from test group by test1         //查看test表中的所有資訊以test1列中的資訊進行分組select * from test order by(test1) desc/asc    //查看test表中的所有資訊以test1列中的資訊進行排序 desc降序排序,asc升序排序

1.2 彙總函式

select max(test1) xx from test            //查看test表中test1列中的最大值  xx為第二別名可有可無select min(test1) from test            //最小值select avg(test1) from test            //平均值select count(test1) from test          //統計test1列中的資料個數select nvl(test1,1) from test          //查詢時要是test1列中的資料為空白時,預設為1顯示出來(1可以更改為任何符合約束條件的值)

1.3 串連查詢

select * from test1,test2 where test1.1=test2.1                  //等值串連select test1.*,test2.* from test1 inner join test2 on test1.1=test2.1          //內串連 select test1.*,test2.* from test1 right outer join test2 on test1.1=test2.1    //外串連1.1  右外串連,顯示時以右面test2表資料為主,右面的表不加限制  通常省略outerselect test1.*,test2.* from test1 left outer join test2 on test1.1=test2.1     //1.2 左外串連  select test1.*,test2.* from test1 full outer join test2 on test1.1=test2.1     //1.3 全外串連 ,顯示全部的列的資料,都不限制

1.3.1

非等值串連

select test1 from test2,test3 where test1 between test2.1 and test3.1  //查詢test1列的值位test2.1和test3.1 中的資料

1.3.2自然串連

1)列名要相同
2)資料類型也要相同,如果不同會出錯
3)不能用表名.列名去限定,可以直接寫列名

select test1.*,test2.* from test1 natural join test2                //自然串連  原理:兩個表中找到的名字相同。資料類型也相同的列進行串連select test1.*,test2.* from test1 natural join test2 using(test3)    //如果有多個列符合條件,用using 選定要串連的列名

1.3.3 聯集查詢

union / union all  union內建distance(去掉重複資料)

多個查詢結果之間用union / union all  串連可以連為一個表進行輸出查看

oracle資料庫之SQL結構化查詢語言 (SQL)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.