1. 程式人生 > >SQL 練習記錄

SQL 練習記錄

-- num mob ini iou desc group by 金額 rom

--1. 統計訂單金額累計>=10000的用戶 最近的5筆交易記錄

select * from (
select t1.ID, t1.[Money], t1.InitialTime, t1.[User], u1.Name,u1.Mobile, row_number() over(partition by t1.[User] order by t1.InitialTime desc) as num
from [TradeFictitious] t1
join
(
select [User] from TradeFictitious
group by [User]
having sum(Money)>=100000
) as j1
on t1.[User] = j1.[User]
left join [User] u1
on t1.[User] = u1.ID)T
where num<=5
go

SQL 練習記錄