select 客户代码,名称,sum(金额)as 总金额,count(A.序号) as 订单数 from B ,A where B.客户代码 = A.客户代码
group by B.客户代码
order by 订单数 desc,总金额 desc