婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > sql server 2008中的apply運算符使用方法

sql server 2008中的apply運算符使用方法

熱門標簽:海南自動外呼系統價格 創業電銷機器人 九鹿林外呼系統怎么收費 浙江地圖標注 滄州營銷外呼系統軟件 松原導航地圖標注 沈陽智能外呼系統代理 電銷機器人虛擬號碼 舞鋼市地圖標注app

Apply運算符可以實現兩個查詢結果的全組合結果,又稱為交叉集合。例如兩個數據組合(A,B)、(A,B),他們的交叉集合為(AA,AB,AA,AB)。

Apply分為Cross Apply和Outer Apply兩種使用方式。具體分析如下:

首先先建立兩個表StudentList和ScoreInfo。腳本語言如下:

復制代碼 代碼如下:

create table StudentList(
id int Identity(1,1) not null,
Name nvarchar(20) not null,
Sex bit not null,
Birthday date not null,
Class nvarchar(2) not null,
Grade nvarchar(2) not null,
regdate date not null,
Primary key (id));

create table ScoreInfo(
id int Identity(1,1) not null primary key,
StudentID int not null,
ClassID int not null,
Score int not null,
TestDate date not null,
regdate date not null);


其中ScoreInfo中的StudentID為StudentList中id的外鍵

插入數據,腳本如下

復制代碼 代碼如下:

insert into StudentList(Name, Sex, Birthday, Class, Grade, regdate) values('張三', 1, '1988-05-28', 1, 8, '2010-05-05');

insert into StudentList(Name, Sex, Birthday, Class, Grade, regdate) values('李四', 1, '1985-09-13', 4, 4, '2010-05-05');

insert into StudentList(Name, Sex, Birthday, Class, Grade, regdate) values('王麗', 0, '1987-11-05', 1, 7, '2010-05-05');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(1, 1, 98, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(1, 2, 92, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(1, 3, 86, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(2, 1, 95, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(2, 2, 94, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(2, 3, 91, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(3, 1, 90, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(3, 2, 88, '2010-04-15', '2010-05-01');

insert into ScoreInfo(StudentID, ClassID, Score, TestDate, regdate) values(3, 3, 90, '2010-04-15', '2010-05-01');


兩個表結構建立完畢,數據也成功插入進去了。為了便于講解在StudentList表中再插入一條記錄
復制代碼 代碼如下:

insert into StudentList(Name, Sex, Birthday, Class, Grade, regdate)
values('李銘', 1, '1989-05-04', 2, 7, '2010-05-05');

輸入以下語句
復制代碼 代碼如下:

select * from StudentList a
cross apply
(select ClassID, Score from ScoreInfo where StudentID=a.id) b;

結果如下

再輸入以下語句

select * from StudentList a
outer apply
(select ClassID, Score from ScoreInfo where StudentID=a.id) b;

結果如下

可以看出Cross Apply和Outer Apply的區別

Cross Apply把語句兩邊的兩個Select查詢結果進行交叉配對,將所有結果展示出來。Cross Apply查詢確保在查詢兩個子集數據的交集時,只有有效信息的集合才被列出來。

OuterApply查詢是把兩個子集的所有組合列了出來,不管數據是否有交叉,全部顯示要配對的數據。

標簽:商洛 公主嶺 寶雞 臺灣 日喀則 咸寧 海口 西藏

巨人網絡通訊聲明:本文標題《sql server 2008中的apply運算符使用方法》,本文關鍵詞  sql,server,2008,中的,apply,運算符,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《sql server 2008中的apply運算符使用方法》相關的同類信息!
  • 本頁收集關于sql server 2008中的apply運算符使用方法的相關信息資訊供網民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章
    主站蜘蛛池模板: 桐梓县| 梁山县| 缙云县| 梁河县| 郧西县| 泰兴市| 广平县| 怀宁县| 保康县| 三门峡市| 磴口县| 乐清市| 东乌珠穆沁旗| 瓦房店市| 霍城县| 武川县| 遂溪县| 谷城县| 简阳市| 和平区| 慈溪市| 佛山市| 竹山县| 辽源市| 酉阳| 从江县| 白水县| 二连浩特市| 湾仔区| 芜湖市| 专栏| 晋州市| 巴彦淖尔市| 华亭县| 沂南县| 黔江区| 萨迦县| 富阳市| 丰宁| 崇礼县| 浏阳市|