SqlServer--資料檢索(查詢)

來源:互聯網
上載者:User

標籤:data   排列   add   res   時間   分行   顯示   別名   檢索   

 

use  MyDataBase1

-- * 表示顯示所有列

-- 查詢語句沒有加where條件表示查詢所有行

select *from TblStudent

---只查詢表中的部分列

select tsid,tsname,tsgender from TblStudent

--根據條件,只查詢部分行(使用where條件式篩選部分行顯示)

select * from TblStudent where tsclassId=5

--為查詢結果集中的列起別名

select tsid as 學生編號,tsname as 學生姓名,tsgender as 性別 from TblStudent

--也可以這樣排列

select

tsid as 學生編號,

tsname as 學生姓名,

tsgender as 性別

from TblStudent

 

select

tsid ‘(學生 編號)‘, --可以輸出空格

tsname 學生 姓名, --不能輸出空格

tsgender 性別

from TblStudent

 

select

學生編號=tsid,

學生姓名=tsname,

性別=tsgender

from TblStudent

 

 

select

學生編號=tsid,

學生姓名=tsname,

性別=tsgender,

婚否=‘否‘

from TblStudent

 

--並不是說select必須配合from一起來使用,可以單獨使用select

select

當前系統時間=getdate()

 

select

班長=‘嚴蒙‘,

班花=‘待定‘,

班草=‘待定‘,

班主任=‘宋詞‘

 

--distinct關鍵字,針對已經查詢出的結果然後去除重複

select distinct * from TblStudent

select distinct tsname,tsgender,tsaddress from TblStudent

 

SqlServer--資料檢索(查詢)

聯繫我們

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