
這是原始數據 想按照brand_id分組 並獲取每個分組total_num最高的前3位
SQL語句為:
select a.* from data a where 3 > (select count(*) from data where brand_id = a.brand_id and total_num > a.total_num ) order by a.brand_id, a.total_num desc;
得到結果


這是原始數據 想按照brand_id分組 並獲取每個分組total_num最高的前3位
SQL語句為:
select a.* from data a where 3 > (select count(*) from data where brand_id = a.brand_id and total_num > a.total_num ) order by a.brand_id, a.total_num desc;
得到結果

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。