我有这样的数据。 Data Table
我希望在时间范围内显示前10名消费(赚取积分)成员。 我的SQL:
SELECT MOBILE,SUM(VALUE) as speding FROM crm_transaction WHERE MOBILE IN (SELECT DISTINCT MOBILE FROM crm_transaction)
答案 0 :(得分:1)
SELECT MOBILE,SUM(VALUE) as speding
FROM crm_transaction
WHERE MOBILE IN (SELECT DISTINCT MOBILE FROM crm_transaction)
group by mobile
答案 1 :(得分:1)
这应该有效
select mobile, sum('value') as speding
from crm_transaction
where time_frame between '<time from>' and '<time to>'
group by mobile
order by speding desc limit 10
您需要将time_frame更改为存储时间的列的实际名称,更改&lt;时间来自&gt;和&lt;时间到&gt;达到你想要的时间价值。