首页 > 数据库技术 > 详细

sqlserver ,left join 不仅可以join表,还可以是一个结果集

时间:2014-06-20 13:58:53      阅读:721      评论:0      收藏:0      [点我收藏+]
SELECT  MA.NAME AS MakeName ,
        M.ID AS ModelId ,
        M.Name AS ModelName ,
        M.Warranty AS ModelWarranty ,
        S.ID,S.NAME,S.StyleWarranty
FROM dbo.Model M
INNER JOIN dbo.Make MA ON MA.Id = M.MakeId
LEFT 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.Id
WHERE M.IsEnabled=1 AND M.IsRemoved=0

  

sqlserver ,left join 不仅可以join表,还可以是一个结果集,布布扣,bubuko.com

sqlserver ,left join 不仅可以join表,还可以是一个结果集

原文:http://www.cnblogs.com/bwlang/p/3795044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!