欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于SQL Server查詢(xún)語(yǔ)句的使用

 更新時(shí)間:2013年04月25日 15:04:53   作者:  
本篇文章介紹了,關(guān)于SQL Server查詢(xún)語(yǔ)句的使用。需要的朋友參考下

一.查詢(xún)第二個(gè)字母是t或者a的雇員的全部信息

復(fù)制代碼 代碼如下:

 select *
 from employees
 where firstname like '_[t,a]%'

注意:在sql中%表示字符串,所以不可像matlab一樣用其注釋?zhuān)瑑蓚€(gè)雙斜線好像也不行,/**/可以,有網(wǎng)友說(shuō)sql單行注釋為--

二.更改字段名

復(fù)制代碼 代碼如下:

 select '名字' = firstname ,'姓氏' = lastname
 from employees
 where firstname like '_[t,a]%'

或者
復(fù)制代碼 代碼如下:

 select  firstname as '名字' , lastname as '姓氏'
 from employees
 where firstname like '_[t,a]%'

三.top關(guān)鍵字
復(fù)制代碼 代碼如下:

 /*檢索出符合條件的前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ù)制代碼 代碼如下:

select *
 from employees
 where title = 'Sales Manager'
 union
 select *
 from employees
 where address is not null

顯示:

服務(wù)器: 消息 8163,級(jí)別 16,狀態(tài) 4,行 1
不能以 DISTINCT 方式選擇 text、ntext 或 image 數(shù)據(jù)類(lèi)型。

復(fù)制代碼 代碼如下:

select *
 from employees
 where title = 'Sales Manager'
 union all
 select *
 from employees
 where address is not null

查詢(xún)分析其中的分析查詢(xún)(對(duì)號(hào))是看下是否有語(yǔ)法錯(cuò)誤(ctrl + F5),執(zhí)行查詢(xún)(右三角)(F5)是顯示結(jié)果的若有語(yǔ)法錯(cuò)誤則不執(zhí)行。

五.compute關(guān)鍵字

compute子句需要以下信息:
 可選的By關(guān)鍵字可按對(duì)一列計(jì)算指定的行聚合
 行聚合函數(shù):sum,avg,min,max,count
 要對(duì)其執(zhí)行行聚合函數(shù)的列
當(dāng)compute帶有可選的By子句時(shí),符合select條件的每個(gè)組都有兩個(gè)結(jié)果集:
 每個(gè)組的第一個(gè)結(jié)果集是明細(xì)行集,其中包含該組的選擇列表信息
 每個(gè)組的第二個(gè)結(jié)果集有一行,其中包含該組COMPUTE子句中所指定的聚合函數(shù)的小記

復(fù)制代碼 代碼如下:

 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)過(guò)

復(fù)制代碼 代碼如下:

 select sex,sclass,score
 from student
 compute sum(score)

相關(guān)文章

最新評(píng)論