多表关联查询
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