码迷,mamicode.com
首页 > 数据库 > 详细

SQL 练习记录

时间:2017-09-18 16:16:40      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:ict   group   initial   def   one   练习   des   having   art   

--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 练习记录

标签:ict   group   initial   def   one   练习   des   having   art   

原文地址:http://www.cnblogs.com/jfeng/p/7543535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!