SQL按条件汇总求和
展开全部
select
sum(case
when
mark
=
0
then
point
else
0
end)
as
Point_0,
sum(case
when
mark
=
1
then
point
else
0
end)
as
Point_1,
Account
from
表A
group
by
Account;
***************
我从不辩解,测试log自己看:
[TEST@ORA1]
SQL>select
*
from
表A;
POINT
MARK
ACCOUNT
----------
----------
----------
20
1
John
30
0
Allen
10
1
Allen
15
1
John
20
0
Michael
25
0
John
6
rows
selected.
[TEST@ORA1]
SQL>select
sum(case
when
mark
=
0
then
point
else
0
end)
as
Point_0,
2
sum(case
when
mark
=
1
then
point
else
0
end)
as
Point_1,
3
Account
4
from
表A
5
group
by
Account;
POINT_0
POINT_1
ACCOUNT
----------
----------
----------
30
10
Allen
25
35
John
20
0
Michael
[TEST@ORA1]
SQL>
---
以上,希望对你有所帮助。
sum(case
when
mark
=
0
then
point
else
0
end)
as
Point_0,
sum(case
when
mark
=
1
then
point
else
0
end)
as
Point_1,
Account
from
表A
group
by
Account;
***************
我从不辩解,测试log自己看:
[TEST@ORA1]
SQL>select
*
from
表A;
POINT
MARK
ACCOUNT
----------
----------
----------
20
1
John
30
0
Allen
10
1
Allen
15
1
John
20
0
Michael
25
0
John
6
rows
selected.
[TEST@ORA1]
SQL>select
sum(case
when
mark
=
0
then
point
else
0
end)
as
Point_0,
2
sum(case
when
mark
=
1
then
point
else
0
end)
as
Point_1,
3
Account
4
from
表A
5
group
by
Account;
POINT_0
POINT_1
ACCOUNT
----------
----------
----------
30
10
Allen
25
35
John
20
0
Michael
[TEST@ORA1]
SQL>
---
以上,希望对你有所帮助。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |