首页 > 代码库 > sqlserver ,left join 不仅可以join表,还可以是一个结果集
sqlserver ,left join 不仅可以join表,还可以是一个结果集
SELECT MA.NAME AS MakeName , M.ID AS ModelId , M.Name AS ModelName , M.Warranty AS ModelWarranty , S.ID,S.NAME,S.StyleWarrantyFROM dbo.Model MINNER JOIN dbo.Make MA ON MA.Id = M.MakeIdLEFT JOIN (SELECT * FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY s1.ModelId ORDER BY s1.updatetime DESC ) rowid , s1.Id,S1.NAME,S1.MODELID,V.Value.value(‘(value/input/content)[1]‘, ‘varchar(50)‘) AS StyleWarranty FROM dbo.Style S1 INNER JOIN dbo.StylePropertyValue v ON S1.Id = v.StyleId WHERE v.PropertyId = 398 ) a WHERE rowid = 1 ) S ON S.ModelId=M.IdWHERE M.IsEnabled=1 AND M.IsRemoved=0
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。