一开始给同事的sql是第二条,但关联查询执行起来慢,同事修改了一些第一条效率明显提升!

  最终优化SQL

CREATE VIEW [dbo].[View_Item_IsLarge]
AS
    SELECT   ItemID, DLMasterChildType
    FROM    dbo.Item_IsLarge AS A
    WHERE   A.Gid IN ( SELECT TOP ( 1 )
                                Gid
                       FROM     dbo.Item_IsLarge
                       WHERE    ( ItemID = A.ItemID )
                       ORDER BY rowModifyDate DESC ) 

GO

 一开始优化的SQL

create view [dbo].[View_Item_IsLarge2]
as
select DLMasterChildType,ItemID from (
select DLMasterChildType,ItemID,ROW_NUMBER() over(partition by ItemID order by rowModifyDate desc )rn
from dbo.Item_IsLarge ) t
where rn=1
GO

相关文章:

  • 2022-01-25
  • 2022-02-06
  • 2021-08-23
猜你喜欢
  • 2022-12-23
  • 2021-09-14
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
相关资源
相似解决方案