sql - 在 SQL 中获取过去 12 个月的汇总交易信息
问题描述
ID# transaction_amount transaction_yr_mon
12345 20 202007
23455 200 202008
12345 34 202007
我想得到以下信息:
ID# Number_of_transactions_in last_12_months total_transaction_amount
12345 2 54
我不知道如何开始在 SQL 中执行此操作,请告知可能的查询可能是什么!
谢谢
解决方案
select id,count(id) as Number_of_transactions_in last_12_months,sum(transaction_amount) as total_transaction_amount
from tablename group by id
或者
select id,count(id) as Number_of_transactions_in last_12_months,sum(transaction_amount) as total_transaction_amount
from tablename group by id,transaction_yr_mon
推荐阅读
- sql - SQL Server 上的死锁问题,更新更新
- python - Conda 环境和在 google collab 中共享
- python - 从函数返回多个对象的最佳方法
- reactjs - 在使用 apache 服务时做出反应构建奇怪的行为
- sql-server - Sql server - 将大型数据库视图复制为具有更新数据副本的表
- voice-recognition - 是否可以将自定义语音命令添加到我的 google home/minis 家庭网络?
- c# - C# 对坐标点进行升序排序
- excel - df.loc 具有跨两个不同数据源的两个条件
- javascript - 尝试创建反应应用程序时出错
- react-native - 反应本机日历如何显示徽章