sql Left Join 右表取一条数据,三种方式

一、(Oracle中已驗證OK)

left join

(select l.* from
(select RealName,CompanyId,row_number() over (partition by CompanyId order by id desc) as rownum1 from vm_User WHERE IsAdmin=1) l
where l.rownum1 = 1 ) w

二、left join (select MAX(RealName),CompanyId, from vm_User GROUP BY CompanyId) W

三、

用OUTER APPLY
select b.* FROM a表 a
OUTER APPLY
(select TOP(1) * from b表 WHERE [Name] = a.[AName] ORDER BY BNo desc) b

原文链接:https://blog.csdn.net/sinat_36500530/article/details/105116381

    A+
发布日期:2023年07月23日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: