S
sbc
Unregistered / Unconfirmed
GUEST, unregistred user!
某表例子如下:
a1 a2 a3 a4 a5
--------------------
k1 0 10 10 10
k1 10 0 10 10
k1 5 5 10 10
k2 10 0 10 10
k3 0 10 10 10
select a1,avp(a2/a4) as av1,avp(a3/a5) as av2,sum(a4) as su1,sum(a5) as su2 from temp group a1
要求改改此查询,使得av1要滤掉a2是0后求平均,av2要滤掉a3是0后求平均,请大家看看如何改。
最好给出一句select。
补充:
select a1,avp(a2/a4) as av1,avp(a3/a5) as av2,sum(a4) as su1,sum(a5) as su2 from temp group a1
的结果为:
a1 av1 av2 su1 su2
---------------------------------------------------------------
k1 (0/10+10/10+5/10)/3=0.5 (10/10+5/10+0/10)/3=0.5 30 30
k2 1 0 10 10
k3 0 1 10 10
改为
a1 av1 av2 su1 su2
---------------------------------------------------------------
k1 (0/10+10/10+5/10)/2=0.75 (10/10+5/10+0/10)/2=0.75 30 30
k2 1 0 10 10
k3 0 1 10 10
a1 a2 a3 a4 a5
--------------------
k1 0 10 10 10
k1 10 0 10 10
k1 5 5 10 10
k2 10 0 10 10
k3 0 10 10 10
select a1,avp(a2/a4) as av1,avp(a3/a5) as av2,sum(a4) as su1,sum(a5) as su2 from temp group a1
要求改改此查询,使得av1要滤掉a2是0后求平均,av2要滤掉a3是0后求平均,请大家看看如何改。
最好给出一句select。
补充:
select a1,avp(a2/a4) as av1,avp(a3/a5) as av2,sum(a4) as su1,sum(a5) as su2 from temp group a1
的结果为:
a1 av1 av2 su1 su2
---------------------------------------------------------------
k1 (0/10+10/10+5/10)/3=0.5 (10/10+5/10+0/10)/3=0.5 30 30
k2 1 0 10 10
k3 0 1 10 10
改为
a1 av1 av2 su1 su2
---------------------------------------------------------------
k1 (0/10+10/10+5/10)/2=0.75 (10/10+5/10+0/10)/2=0.75 30 30
k2 1 0 10 10
k3 0 1 10 10