select a.卡号, a.姓名,a.ma,count(*) as pm from (
SELECT 卡号, 姓名, sum(消费金额) as ma
FROM 表1 group by 卡号, 姓名) a left join
(SELECT 卡号, 姓名, sum(消费金额) as ma FROM 表1 group by 卡号, 姓名) b
on a.ma<=b.ma
group by a.卡号, a.姓名,a.ma
order by 4
select a.卡号, a.姓名,a.ma,count(*) as pm from (
SELECT 卡号, 姓名, sum(消费金额) as ma
FROM 表1 group by 卡号, 姓名) a left join
(SELECT 卡号, 姓名, sum(消费金额) as ma FROM 表1 group by 卡号, 姓名) b
on a.ma<=b.ma
group by a.卡号, a.姓名,a.ma
order by 4
SELECT a.卡号, a.姓名, a.ma, a.cs, count(*) AS pm
FROM (SELECT 卡号, 姓名, sum(消费金额) as ma,count(*) as cs
FROM 表1 group by 卡号, 姓名) AS a LEFT JOIN (SELECT 卡号, 姓名, sum(消费金额) as ma FROM 表1 group by 卡号, 姓名) AS b ON a.ma<=b.ma
GROUP BY a.卡号, a.姓名, a.ma, a.cs
ORDER BY 4;
SELECT a.卡号, a.姓名, a.ma, a.cs, count(*) AS pm
FROM (SELECT 卡号, 姓名, sum(消费金额) as ma,count(*) as cs
FROM 表1 group by 卡号, 姓名) AS a LEFT JOIN (SELECT 卡号, 姓名, sum(消费金额) as ma FROM 表1 group by 卡号, 姓名) AS b ON a.ma<=b.ma
GROUP BY a.卡号, a.姓名, a.ma, a.cs
ORDER BY 4;