数码资讯
浅析SQLServer中的存在与内插
在和存在这两个函数是相似的,但由于不同的优化方案,通常不存在比不快,因为不存在可以结合使用两个不在算法是不好的,但存在优于在,因为使用这个在可能更多的算法。 例如,现在有两个数据集,# temptable1左边和右边# temptable2。现在有以下问题: 1。两个集合的交集 2。不属于tempt
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
在和存在这两个函数是相似的,但由于不同的优化方案,通常不存在比不快,因为不存在可以结合使用两个不在算法是不好的,但存在优于在,因为使用这个在可能更多的算法。
例如,现在有两个数据集,# temptable1左边和右边# temptable2。现在有以下问题:
1。两个集合的交集
2。不属于temptable1集# temptable2设定
首先创建两个临时表:
创建表# temptable1
(
论证1 nvarchar(50),
论证2 varchar(20),
argument3 DateTime,
argument4 int
);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher001 ','13023218757,getdate()-1,1);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher002 ','23218757,getdate()- 2);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher003 ','13018757,getdate()- 3);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher004 ','13023257,getdate()- 4);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher005 ','13023218,getdate()-5);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher006 ','13023218,getdate()- 6,6);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher007 ','13023218,getdate()- 7,7);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher008 ','13023218,getdate()- 8,8);
创建表# temptable2
(
论证1 nvarchar(50),
论证2 varchar(20),
argument3 DateTime,
argument4 int
);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher001 ','13023218757,getdate()-1,1);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher0010 ','23218757,getdate()- 10,10);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher003 ','13018757,getdate()- 3);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher004 ','13023257,getdate()- 4);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher009 ','13023218,getdate()- 9,9);
例如,我现在使用# temptable1和# temptable2的论证1作为参考
1。两个集合的交集:
1)在模式
SELECT * FROM # temptable2论证1在哪里
(选择# temptable1论证1)
2)存在模式
Select * from #tempTable2 T2 where exists
(SELECT * FROM # temptable1 T1,T1,T2论证1 =。论证1)
2。找到一套不属于temptable1一套# temptable2
1)在模式
SELECT * FROM # temptable1在论证1不
(选择# temptable2论证1)
2)存在模式
SELECT * FROM # temptable1 T1的地方不存在
(SELECT * FROM # temptable2 T2在T1。论证1 = T2。论证1)
例如,现在有两个数据集,# temptable1左边和右边# temptable2。现在有以下问题:
1。两个集合的交集
2。不属于temptable1集# temptable2设定
首先创建两个临时表:
创建表# temptable1
(
论证1 nvarchar(50),
论证2 varchar(20),
argument3 DateTime,
argument4 int
);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher001 ','13023218757,getdate()-1,1);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher002 ','23218757,getdate()- 2);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher003 ','13018757,getdate()- 3);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher004 ','13023257,getdate()- 4);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher005 ','13023218,getdate()-5);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher006 ','13023218,getdate()- 6,6);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher007 ','13023218,getdate()- 7,7);
插入# temptable1(论证1,论证2,argument3,argument4)
值('preacher008 ','13023218,getdate()- 8,8);
创建表# temptable2
(
论证1 nvarchar(50),
论证2 varchar(20),
argument3 DateTime,
argument4 int
);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher001 ','13023218757,getdate()-1,1);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher0010 ','23218757,getdate()- 10,10);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher003 ','13018757,getdate()- 3);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher004 ','13023257,getdate()- 4);
插入# temptable2(论证1,论证2,argument3,argument4)
值('preacher009 ','13023218,getdate()- 9,9);
例如,我现在使用# temptable1和# temptable2的论证1作为参考
1。两个集合的交集:
1)在模式
SELECT * FROM # temptable2论证1在哪里
(选择# temptable1论证1)
2)存在模式
Select * from #tempTable2 T2 where exists
(SELECT * FROM # temptable1 T1,T1,T2论证1 =。论证1)
2。找到一套不属于temptable1一套# temptable2
1)在模式
SELECT * FROM # temptable1在论证1不
(选择# temptable2论证1)
2)存在模式
SELECT * FROM # temptable1 T1的地方不存在
(SELECT * FROM # temptable2 T2在T1。论证1 = T2。论证1)
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。