You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL需求:计算客户近30天消费额及最高消费商品

问题内容

现有数据表

transaction_details表

交易ID(transaction_id)客户ID(customer_id)商品ID(item_id)购买数量(item_number)交易时间(transaction_dttm)
776512312022-01-15
125421242022-02-03
333235622022-02-15
765814312022-03-01
723145612022-01-15
723122322022-01-29

dict_item_prices表

商品ID(item_id)商品名称(item_name)商品价格(item_price)生效起始日期(valid_from_dt)生效截止日期(valid_to_dt)
23手机110002022-01-012022-12-31
12笔记本电脑50002022-01-022022-12-31
56杯子502022-01-022022-12-31
43眼镜7002022-01-012022-12-31

需求说明

计算客户在报表生成当日起近30天的消费金额,并找出该客户在此期间消费金额最高的商品名称。计算时需关联dict_item_prices表中交易发生时有效的商品价格,未在此期间产生交易的客户不纳入最终结果。

示例结果

客户ID(customer_id)近30天消费额(amount_spent_lm)最高消费商品(top_item_lm)
1700眼镜
220000笔记本电脑
3100杯子

内容的提问来源于stack exchange,提问作者useless

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 01:55:34