表TAB
F1 F2 f3
1 1 3
2 5 2
1 3 2
1 10 5
2 2 4
1 7 1当f3>2 时 sum(f2)
否则 sum(f3)
自己写的有错
select case when f3>2 then sum(f2)
else sum(f3)
end num
from tab
group by f1提示:非group by 表达式
F1 F2 f3
1 1 3
2 5 2
1 3 2
1 10 5
2 2 4
1 7 1当f3>2 时 sum(f2)
否则 sum(f3)
自己写的有错
select case when f3>2 then sum(f2)
else sum(f3)
end num
from tab
group by f1提示:非group by 表达式
sum(case when f3>2 then f3 else 0 end) as sum_f3
from tab group by f1