多表关联查询
select w2.n,w1.* from (
select fpr.flag AS reportflag,fpr.id AS reportid,fpr.userid,fpl.* from ndb_fp_report fpr left outer join ndb_fp_log fpl on fpl.id=fpr.fpid
) w1,(
select top 20 row_number() OVER(order by g.id desc) n,g.id from ndb_fp_report t left outer join ndb_fp_log g on g.id = t.fpid where 1=1 and starttime between '2019-04-27 00:00:00' and '2019-04-28 23:59:59'
) w2
where w1.id=w2.id and w2.n > 0 order by w2.n asc
单表查询
SELECT w2.n,w1* FROM v_account w1,(SELECT TOP 50 row_number() OVER (ORDER BY Id DESC) n, Id FROM v_account) w2 WHERE w1.Id = w2.Id AND w2.n > 0 ORDER BY w2.n ASC
参考:https://blog.youkuaiyun.com/qiaqia609/article/details/41445233

本文详细解析了复杂SQL查询中的多表关联与单表查询技巧,包括使用LEFT OUTER JOIN进行数据关联,以及如何利用TOP和ROW_NUMBER()进行结果排序与限制。通过具体案例,展示了如何在大量数据中高效检索所需信息。
496

被折叠的 条评论
为什么被折叠?



