久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='t0cVz'><style id='t0cVz'><dir id='t0cVz'><q id='t0cVz'></q></dir></style></legend>

      <small id='t0cVz'></small><noframes id='t0cVz'>

        <i id='t0cVz'><tr id='t0cVz'><dt id='t0cVz'><q id='t0cVz'><span id='t0cVz'><b id='t0cVz'><form id='t0cVz'><ins id='t0cVz'></ins><ul id='t0cVz'></ul><sub id='t0cVz'></sub></form><legend id='t0cVz'></legend><bdo id='t0cVz'><pre id='t0cVz'><center id='t0cVz'></center></pre></bdo></b><th id='t0cVz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='t0cVz'><tfoot id='t0cVz'></tfoot><dl id='t0cVz'><fieldset id='t0cVz'></fieldset></dl></div>
      1. <tfoot id='t0cVz'></tfoot>
          <bdo id='t0cVz'></bdo><ul id='t0cVz'></ul>
      2. 當我們在 SQL Server 2012 中進行交叉應用和內部連接

        When we go for cross apply and when we go for inner join in SQL Server 2012(當我們在 SQL Server 2012 中進行交叉應用和內部連接時)

            <tfoot id='YhmfE'></tfoot>
              <tbody id='YhmfE'></tbody>

              <bdo id='YhmfE'></bdo><ul id='YhmfE'></ul>
              <legend id='YhmfE'><style id='YhmfE'><dir id='YhmfE'><q id='YhmfE'></q></dir></style></legend>
                1. <i id='YhmfE'><tr id='YhmfE'><dt id='YhmfE'><q id='YhmfE'><span id='YhmfE'><b id='YhmfE'><form id='YhmfE'><ins id='YhmfE'></ins><ul id='YhmfE'></ul><sub id='YhmfE'></sub></form><legend id='YhmfE'></legend><bdo id='YhmfE'><pre id='YhmfE'><center id='YhmfE'></center></pre></bdo></b><th id='YhmfE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YhmfE'><tfoot id='YhmfE'></tfoot><dl id='YhmfE'><fieldset id='YhmfE'></fieldset></dl></div>

                  <small id='YhmfE'></small><noframes id='YhmfE'>

                  本文介紹了當我們在 SQL Server 2012 中進行交叉應用和內部連接時的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個關于 SQL Server 的小問題.什么時候用cross apply,什么時候用inner join?為什么在 SQL Server 中完全使用 cross apply?

                  I have small question about SQL Server. When do we use cross apply, and when do we use inner join? Why use cross apply at all in SQL Server?

                  我有 emp、dept 表;基于這兩個表,我編寫了一個 inner joincross apply 查詢,如下所示:

                  I have emp, dept tables; based on those two tables, I write an inner join and cross apply query like this:

                  ----using cross apply
                  SELECT * 
                  FROM Department D 
                  CROSS APPLY 
                      (SELECT * 
                       FROM Employee E 
                       WHERE E.DepartmentID = D.DepartmentID) A 
                  
                  ----using inner join 
                  SELECT * 
                  FROM Department D 
                  INNER JOIN Employee E ON D.DepartmentID = E.DepartmentID 
                  

                  兩個查詢返回相同的結果.

                  Both queries return the same result.

                  這里為什么在 SQL Server 中需要 cross apply ?有性能差異嗎?你能告訴我嗎?

                  Here why is cross apply needed in SQL Server? Is there performance difference? Can you please tell me?

                  我們什么時候使用cross apply,什么時候使用inner join?這些查詢之間有什么性能差異嗎?請告訴我在 SQL Server 中編寫此查詢的最佳方法是什么.

                  When will we use cross apply and when inner join? Any performance difference between these queries? Please tell me which is the best way to write this query in SQL Server.

                  推薦答案

                  INNER JOINCROSS APPLY(同 LEFT JOINOUTER APPLY) 密切相關.在您的示例中,我假設引擎會找到相同的執行計劃.

                  INNER JOIN and CROSS APPLY (same with LEFT JOIN and OUTER APPLY) are very closely related. In your example I'd assume, that the engine will find the same execution plan.

                  • JOIN 是兩個集合之間的一個條件鏈接
                  • 一個 APPLY 是一個 row-wise 子調用
                  • A JOIN is a link between two sets over a condition
                  • an APPLY is a row-wise sub-call

                  但是 - 如上所述 - 優化器非常聰明,并且會 - 至少在這種簡單的情況下 - 理解它歸結為相同.

                  But - as mentioned above - the optimizer is very smart and will - at least in such easy cases - understand, that it comes down to the same.

                  • JOIN 將嘗試在指定條件下收集子集并將其鏈接
                  • APPLY 將嘗試一遍又一遍地使用當前行的值調用相關結果.
                  • The JOIN will try to collect the sub-set and link it over the specified condition
                  • The APPLY will try to call the related result with the current row's values over and over.

                  區別在于調用 table-valued-functions(應該是 inline-syntax!),與 XML 方法 .nodes()以及更復雜的場景.

                  Differences are in calling table-valued-functions (should be inline-syntax!), with XML-method .nodes() and with more complex scenarios.

                  ...使用按行計算的結果,就像使用變量一樣:

                  ...to use the result of a row-wise calculation like you'd use a variable:

                  DECLARE @dummy TABLE(ID INT IDENTITY, SomeString VARCHAR(100));
                  INSERT INTO @dummy VALUES('Want to split/this at the two/slashes.'),('And/this/also');
                  
                  SELECT d.ID
                        ,d.SomeString
                        ,pos1
                        ,pos2
                        ,LEFT(d.SomeString,pos1-1)
                        ,SUBSTRING(d.SomeString,pos1+1,pos2-pos1-1)
                        ,SUBSTRING(d.SomeString,pos2+1,1000)
                  FROM @dummy AS d
                  CROSS APPLY(SELECT CHARINDEX('/',d.SomeString) AS pos1) AS x
                  CROSS APPLY(SELECT CHARINDEX('/',d.SomeString,x.pos1+1) AS pos2) AS y
                  

                  這與以下內容相同,但更易于閱讀(和輸入):

                  This is the same as the following, but much easier to read (and type):

                  SELECT d.ID
                        ,d.SomeString
                        ,LEFT(d.SomeString,CHARINDEX('/',d.SomeString)-1)
                        ,SUBSTRING(d.SomeString,CHARINDEX('/',d.SomeString)+1,CHARINDEX('/',d.SomeString,(CHARINDEX('/',d.SomeString)+1))-(CHARINDEX('/',d.SomeString)+1))
                        ,SUBSTRING(d.SomeString,CHARINDEX('/',d.SomeString,(CHARINDEX('/',d.SomeString)+1))+1,1000)
                  FROM @dummy AS d
                  

                  XML 方法的一個例子 .nodes()

                  DECLARE @dummy TABLE(SomeXML XML)
                  INSERT INTO @dummy VALUES
                  (N'<root>
                    <a>a1</a>
                    <a>a2</a>
                    <a>a3</a>
                    <b>Here is b!</b>
                  </root>');
                  
                  SELECT All_a_nodes.value(N'.',N'nvarchar(max)')
                  FROM @dummy
                  CROSS APPLY SomeXML.nodes(N'/root/a') AS A(All_a_nodes);
                  

                  結果

                  a1
                  a2
                  a3
                  

                  一個內聯函數調用的例子

                  CREATE FUNCTION dbo.TestProduceRows(@i INT)
                  RETURNS TABLE
                  AS
                  RETURN
                      SELECT TOP(@i) ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS Nr FROM master..spt_values
                  GO
                  
                  CREATE TABLE dbo.TestData(ID INT IDENTITY, SomeString VARCHAR(100),Number INT);
                  INSERT INTO dbo.TestData VALUES
                   ('Show me once',1)
                  ,('Show me twice',2)
                  ,('Me five times!',5);
                  
                  SELECT *
                  FROM TestData
                  CROSS APPLY dbo.TestProduceRows(Number) AS x;
                  
                  GO
                  DROP TABLE dbo.TestData;
                  DROP FUNCTION dbo.TestProduceRows;
                  

                  結果

                  1   Show me once    1   1
                  2   Show me twice   2   1
                  2   Show me twice   2   2
                  3   Me five times!  5   1
                  3   Me five times!  5   2
                  3   Me five times!  5   3
                  3   Me five times!  5   4
                  3   Me five times!  5   5
                  

                  這篇關于當我們在 SQL Server 2012 中進行交叉應用和內部連接時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Break down a table to pivot in columns (SQL,PYSPARK)(分解表以按列進行透視(SQL、PYSPARK))
                  Spark giving Null Pointer Exception while performing jdbc save(Spark在執行jdbc保存時給出空指針異常)
                  execute query on sqlserver using spark sql(使用 spark sql 在 sqlserver 上執行查詢)
                  executeSql failing after putSql processor(putSql處理器后executeSql失敗)
                  How can I compare the one line in one CSV with all lines in another CSV file?(如何將一個 CSV 中的一行與另一個 CSV 文件中的所有行進行比較?)
                  How to map the column wise data in flowfile in NiFi?(如何在 NiFi 中映射流文件中的列數據?)

                  • <i id='VIFWr'><tr id='VIFWr'><dt id='VIFWr'><q id='VIFWr'><span id='VIFWr'><b id='VIFWr'><form id='VIFWr'><ins id='VIFWr'></ins><ul id='VIFWr'></ul><sub id='VIFWr'></sub></form><legend id='VIFWr'></legend><bdo id='VIFWr'><pre id='VIFWr'><center id='VIFWr'></center></pre></bdo></b><th id='VIFWr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VIFWr'><tfoot id='VIFWr'></tfoot><dl id='VIFWr'><fieldset id='VIFWr'></fieldset></dl></div>
                          <tbody id='VIFWr'></tbody>
                          <bdo id='VIFWr'></bdo><ul id='VIFWr'></ul>

                          <tfoot id='VIFWr'></tfoot>
                        • <legend id='VIFWr'><style id='VIFWr'><dir id='VIFWr'><q id='VIFWr'></q></dir></style></legend>

                          <small id='VIFWr'></small><noframes id='VIFWr'>

                            主站蜘蛛池模板: 欧洲亚洲一区二区三区 | 天堂色综合 | 久久精品网 | 一本大道久久a久久精二百 国产成人免费在线 | 精品中文字幕一区 | 国产午夜在线观看 | 中文字幕日韩欧美 | 欧美黄色免费网站 | 日韩国产欧美视频 | 国产精品美女久久久久久免费 | 精品视频一区二区 | 亚洲成人在线网 | 欧美啊v在线观看 | 99久久免费精品 | 伊人无码高清 | 国产乱精品一区二区三区 | 亚洲日本一区二区 | 中文字幕视频在线观看 | 精品乱人伦一区二区三区 | 在线观看国产 | 日韩av一区二区在线观看 | 国产精品久久久久久久久免费相片 | 亚洲欧洲激情 | 亚洲不卡在线观看 | av一区二区三区四区 | 婷婷在线免费 | 真人毛片| 九九精品在线 | 国产精品福利视频 | 婷婷综合色 | 亚洲精品日本 | 91影院在线观看 | 免费在线日韩 | 日韩精品一区二区三区在线观看 | 四虎在线观看 | 精品久久亚洲 | 久久综合伊人 | 欧美精品综合在线 | 国产99视频精品免费视频7 | 国产精品永久在线观看 | 久久久久久久久99 |