国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

關于SQL Server查詢語句的使用

2024-08-31 00:47:30
字體:
來源:轉載
供稿:網友

一.查詢第二個字母是t或者a的雇員的全部信息

復制代碼 代碼如下:www.CuoXIn.com

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

注意:在sql中%表示字符串,所以不可像matlab一樣用其注釋,兩個雙斜線好像也不行,/**/可以,有網友說sql單行注釋為--

二.更改字段名

復制代碼 代碼如下:www.CuoXIn.com

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

或者
復制代碼 代碼如下:www.CuoXIn.com

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

三.top關鍵字
復制代碼 代碼如下:www.CuoXIn.com

/*檢索出符合條件的前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關鍵字
注意:標準sql只提供了并操作,未提供交(intersection)和差(minus)操作。
復制代碼 代碼如下:www.CuoXIn.com

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

顯示:

服務器: 消息 8163,級別 16,狀態 4,行 1
不能以 DISTINCT 方式選擇 text、ntext 或 image 數據類型。

復制代碼 代碼如下:www.CuoXIn.com

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

查詢分析其中的分析查詢(對號)是看下是否有語法錯誤(ctrl + F5),執行查詢(右三角)(F5)是顯示結果的若有語法錯誤則不執行。

五.compute關鍵字

compute子句需要以下信息:
可選的By關鍵字可按對一列計算指定的行聚合
行聚合函數:sum,avg,min,max,count
要對其執行行聚合函數的列
當compute帶有可選的By子句時,符合select條件的每個組都有兩個結果集:
每個組的第一個結果集是明細行集,其中包含該組的選擇列表信息
每個組的第二個結果集有一行,其中包含該組COMPUTE子句中所指定的聚合函數的小記

復制代碼 代碼如下:www.CuoXIn.com

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

注意:order by是必須的,并且 compute by后的參數應該在order by后的參數中出現過

復制代碼 代碼如下:www.CuoXIn.com

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仁怀市| 仁怀市| 黄冈市| 梓潼县| 敦化市| 晋江市| 宜都市| 永仁县| 绥江县| 昌都县| 新龙县| 广宗县| 宽城| 武邑县| 宁德市| 萨嘎县| 德清县| 百色市| 微山县| 壶关县| 辰溪县| 神池县| 天柱县| 石河子市| 德安县| 遂宁市| 永仁县| 遂溪县| 威信县| 衡阳县| 旌德县| 扬中市| 仙居县| 龙岩市| 杭锦后旗| 鄄城县| 屏山县| 永宁县| 东海县| 晋江市| 五寨县|