--统计总数 select sum(max(交易金额)) from T where ……--时间条件 GROUP BY 交易编号 --按客户统计 select 客户代码,sum(交易金额) 交易金额 from( select 交易编号,客户代码,max(交易金额) 交易金额 from T where ……--时间条件 GROUP BY 交易编号,客户代码 )group by 客户代码
--统计总数 select sum(交易金额) from ( select distinct 交易编号,交易金额 from T where …时间条件等…)--按客户统计 select 客户代码,sum(交易金额) from ( select distinct 客户代码,交易编号,交易金额 from T where …时间条件等…) group by 客户代码
--统计总数
select sum(max(交易金额))
from T
where ……--时间条件
GROUP BY 交易编号
--按客户统计
select 客户代码,sum(交易金额) 交易金额
from(
select 交易编号,客户代码,max(交易金额) 交易金额
from T
where ……--时间条件
GROUP BY 交易编号,客户代码
)group by 客户代码
--统计总数
select sum(交易金额)
from ( select distinct 交易编号,交易金额 from T where …时间条件等…)--按客户统计
select 客户代码,sum(交易金额)
from ( select distinct 客户代码,交易编号,交易金额 from T where …时间条件等…) group by 客户代码
我之前不知道,原来当同一个编号所代表的金额相同时可以直接用distinct。我用的是2楼的方法,不过还是很感谢版主哦~