分组、求和、求最大值:select G,MAX(SUM(V)) V1 from T group by G
求比值:
select T.G,SUM(T.V)/A.V1
from T,
(select G,MAX(SUM(V)) V1 from T group by G) A
where T.G=A.G
group by T.G
试试看,我没测试。
select (select avg(sales) from 表名 b where (a.date-b.date) between 0 and 20) as [前20日平均销量],* from 表名 aSELECT i.uid,sum(deposit+ddeposit+money) as allmoney FROM另外,因为你是多个表的左联接,考虑到有NULL记录的存在,建议你用函数ifnull处理下,避免由于NULL而造成结果有误,最终改成这样:
SELECT i.uid,sum(ifnull(deposit,0)+ifnull(ddeposit,0)+ifnull(money,0)) as allmoney
FROM pw_memberinfo i LEFT JOIN pw_members m ON m.uid=i.uid LEFT JOIN pw_memberdata d ON i.uid=d.uid
where ifnull(deposit,0)+ifnull(ddeposit,0)+ifnull(money,0)>2000
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)