分组后取最后一条记录

在没有窗口函数的MySQL中,如何查询每个用户的最新订阅记录和总费用?文章通过示例数据展示了如何使用SPL脚本来解决这个问题,得到每个用户最新的套餐名称和总消费金额。
摘要由CSDN通过智能技术生成

【问题】
I have a table of users,subscription packages and various user subscriptions. I need to fetch a sum of all subscription cost and display the latest/last subscription. The latest subscription is the subscription with the highest subscription_id. How can I write my query? My tables are listed as below.

Users table

user_id name

1 John

2 Jane

3 Matthew

Subscription Packages table

package_id package_name

1 Basic

2 Advanced

3 Premium

User Subscriptions

subscription_id user_id package_id subscription_cost date

1 1 1 2 2014-04-01

2 2 1 2 2014-04-01

3 3 1 2 2014-04-01

4 1 1 2 2014-05-01

5 1 2 3.5 2014-06-01

6 2 2 3.5 2014-06-01

7 2 2 3.5 2014-07-01

8 1 3 5 2014-07-01

9 3 2 5 2014-07-01

10 2 2 3.5 2014-08-01

11 1 1 2 2014-08-01

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值