標籤: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--資料檢索(查詢)