select a.customid,round(sum(a.sale_amount*b.price),2) tt from 2002a a,2002b b,2002c c where a.customid=c.customid and a.productid=b.productid group
by a.customid order by tt desc
根据上述求出来的表在增加一列 (排序列) 怎么写sql
SELECT a.customid, round(sum(a.sale_amount * b.price), 2) tt FROM 2002a a, 2002b b, 2002c c WHERE a.customid = c.customid AND a.productid = b.productid GROUP BY a.customid ORDER BY round(sum(a.sale_amount * b.price), 2) DESC
========
= =#
参考下面的sql,在外面再套一层即可;
http://suo.im/5QQDC8
select (@i:=@i+1) as 序号,a.customid,round(sum(a.sale_amount*b.price),2) tt from 2002a a,2002b b,2002c c ,(select @i:=0)where a.customid=c.customid and a.productid=b.productid groupby a.customid order by tt desc
加个临时参数做排序用吧