關(guān)于SQL Server查詢語句的使用_Mssql數(shù)據(jù)庫教程
推薦:SQL Server的基本功能性語句介紹本篇文章介紹了,SQL Server的基本功能性語句。需要的朋友參考下
一.查詢第二個字母是t或者a的雇員的全部信息
復(fù)制代碼 代碼如下:www.hl5o.cn
select *
from employees
where firstname like '_[t,a]%'
注意:在sql中%表示字符串,所以不可像matlab一樣用其注釋,兩個雙斜線好像也不行,/**/可以,有網(wǎng)友說sql單行注釋為--
二.更改字段名
復(fù)制代碼 代碼如下:www.hl5o.cn
select '名字' = firstname ,'姓氏' = lastname
from employees
where firstname like '_[t,a]%'
或者
復(fù)制代碼 代碼如下:www.hl5o.cn
select firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'
三.top關(guān)鍵字
復(fù)制代碼 代碼如下:www.hl5o.cn
/*檢索出符合條件的前70%條記錄*/
select top 70 percent firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'1 /*檢索出符合條件的前2條記錄*/
select top 2 firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'
四.union關(guān)鍵字
注意:標(biāo)準(zhǔn)sql只提供了并操作,未提供交(intersection)和差(minus)操作。
復(fù)制代碼 代碼如下:www.hl5o.cn
select *
from employees
where title = 'Sales Manager'
union
select *
from employees
where address is not null
顯示:
服務(wù)器: 消息 8163,級別 16,狀態(tài) 4,行 1
不能以 DISTINCT 方式選擇 text、ntext 或 image 數(shù)據(jù)類型。
復(fù)制代碼 代碼如下:www.hl5o.cn
select *
from employees
where title = 'Sales Manager'
union all
select *
from employees
where address is not null
查詢分析其中的分析查詢(對號)是看下是否有語法錯誤(ctrl + F5),執(zhí)行查詢(右三角)(F5)是顯示結(jié)果的若有語法錯誤則不執(zhí)行。
五.compute關(guān)鍵字
compute子句需要以下信息:
可選的By關(guān)鍵字可按對一列計算指定的行聚合
行聚合函數(shù):sum,avg,min,max,count
要對其執(zhí)行行聚合函數(shù)的列
當(dāng)compute帶有可選的By子句時,符合select條件的每個組都有兩個結(jié)果集:
每個組的第一個結(jié)果集是明細(xì)行集,其中包含該組的選擇列表信息
每個組的第二個結(jié)果集有一行,其中包含該組COMPUTE子句中所指定的聚合函數(shù)的小記
復(fù)制代碼 代碼如下:www.hl5o.cn
select sex,sclass,score
from student
order by sex
compute sum(score) by sex

注意:order by是必須的,并且 compute by后的參數(shù)應(yīng)該在order by后的參數(shù)中出現(xiàn)過
復(fù)制代碼 代碼如下:www.hl5o.cn
select sex,sclass,score
from student
compute sum(score)

分享:SQL Server控制語句的基本應(yīng)用本篇文章介紹了,SQL Server控制語句的基本應(yīng)用。需要的朋友參考下
相關(guān)Mssql數(shù)據(jù)庫教程:
- sql 語句練習(xí)與答案
- 深入C++ string.find()函數(shù)的用法總結(jié)
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法
- sql刪除重復(fù)數(shù)據(jù)的詳細(xì)方法
- SQL SERVER 2000安裝教程圖文詳解
- 使用sql server management studio 2008 無法查看數(shù)據(jù)庫,提示 無法為該請求檢索數(shù)據(jù) 錯誤916解決方法
- SQLServer日志清空語句(sql2000,sql2005,sql2008)
- Sql Server 2008完全卸載方法(其他版本類似)
- sql server 2008 不允許保存更改,您所做的更改要求刪除并重新創(chuàng)建以下表
- SQL Server 2008 清空刪除日志文件(瞬間日志變幾M)
- Win7系統(tǒng)安裝MySQL5.5.21圖解教程
- 將DataTable作為存儲過程參數(shù)的用法實例詳解
- 相關(guān)鏈接:
- 教程說明:
Mssql數(shù)據(jù)庫教程-關(guān)于SQL Server查詢語句的使用
。