(select table5.shopareaid,table5.usersid ,table5.username from (select sg.shopareaid,u1.usersid,u1.username,row_number() OVER(PARTITION BY sg.shopareaid ORDER BY sg.shopareaid desc) numbers from shops s, shopgroup sg,users u1 where s.shopgroupid = sg.shopgroupid and u1.companysid=7 and u1.usertitle = 40 and u1.status<=2 and s.shopsid=u1.residentshopid) table5 where table5.numbers=1) table1,
.
原文:http://www.cnblogs.com/mayay/p/6925078.html