關(guān)于SQL Server查詢語句的使用
一.查詢第二個字母是t或者a的雇員的全部信息
select *
from employees
where firstname like '_[t,a]%'
注意:在sql中%表示字符串,所以不可像matlab一樣用其注釋,兩個雙斜線好像也不行,/**/可以,有網(wǎng)友說sql單行注釋為--
二.更改字段名
select '名字' = firstname ,'姓氏' = lastname
from employees
where firstname like '_[t,a]%'
或者
select firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'
三.top關(guān)鍵字
/*檢索出符合條件的前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)鍵字
注意:標準sql只提供了并操作,未提供交(intersection)和差(minus)操作。
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ù)類型。
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ù)的列
當compute帶有可選的By子句時,符合select條件的每個組都有兩個結(jié)果集:
每個組的第一個結(jié)果集是明細行集,其中包含該組的選擇列表信息
每個組的第二個結(jié)果集有一行,其中包含該組COMPUTE子句中所指定的聚合函數(shù)的小記
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)過
select sex,sclass,score
from student
compute sum(score)
相關(guān)文章
快速插入大量數(shù)據(jù)的asp.net代碼(Sqlserver)
目標數(shù)據(jù)庫只能是Sqlserver 來源數(shù)據(jù)庫 無所謂 只要能用ado.net 將來源數(shù)據(jù)讀取到Dataset或者Datareader 中就可以了。2011-02-02SQL SERVER中各類觸發(fā)器的完整語法及參數(shù)說明
這篇文章主要介紹了SQL SERVER中各類觸發(fā)器的完整語法及參數(shù),需要的朋友可以收藏下2013-08-08sql函數(shù) REGEXP_REPLACE的使用方法小結(jié)
假設(shè)您的數(shù)據(jù)在正文中有不必要的空格,您希望用單個空格來替換它們,利用REPLACE函數(shù) ,這篇文章給大家介紹sql函數(shù) REGEXP_REPLACE的使用方法小結(jié),感興趣的朋友一起看看吧2023-11-11sqlserver 復(fù)制表 復(fù)制數(shù)據(jù)庫存儲過程的方法
復(fù)制整個SqlServer數(shù)據(jù)庫的問題的比較好的方法2008-02-02