Home > database >  Who help a SQL issue
Who help a SQL issue

Time:11-05

Everybody is good, I want to statistics the column values corresponding to the amount of the same statistics, how to use SQL, thank you

CodePudding user response:

Type is 18 added up, type is 15 sum up, with a cumulative value of 18-15 accumulated value

CodePudding user response:

SELECT SUM (DECODE (OPERATION, 18, VIRTUALMONEY, 0)) - the SUM (DECODE (OPERATION, 15, VIRTUALMONEY, 0))
The FROM TABLE_NAME GROUP BY CARDNO.

CodePudding user response:

 with t as (
Select '6215990' cardno, 'WuQiaoZhen' username, '15' operation, 1 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '15' operation, 2 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '15' operation, 3 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '18' operation, 4 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '18' operation, 5 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '18' operation, 6 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '18' operation, 7 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '18' operation, 8 virtualmoney from dual
Union all
Select '6215990' cardno, 'WuQiaoZhen' username, '19' operation, 9 virtualmoney from dual

)
Select sum (decode (operation, '18' virtualmoney, - virtualmoney)) from t where operation in (' 15 ', '18);
  • Related