Home > database >  Mysql as accumulative calculation phase left how to do?
Mysql as accumulative calculation phase left how to do?

Time:11-25



The result is that


Not a normal group by

CodePudding user response:

The second figure ID is which come of

CodePudding user response:

reference 1st floor AHUA1001 response:
the second figure where the ID is

ID can not to do

CodePudding user response:

I didn't understand, is the results you want,

CodePudding user response:

Do you mean groupby adjacent line, so the question is to add a line field, the adjacent line and field name equal field values, adding a judgment, when groupby this field to add just can't learn SQL, but recently I operate excel in python, this will fill in python to do good, finally to excel guide into the database file

CodePudding user response:

Open the window function understanding once,

CodePudding user response:

reference 4 floor ipconfigadl response:
do you mean groupby adjacent line, then the problem is to add a line fields, make the adjacent line and field name equal field values, adding a judgment when groupby, just can't learn this field to add SQL, but recently I operate excel in python, this will fill in python to do good, finally to excel guide into the database file

This to mean, it seems that the SQL is difficult to write

CodePudding user response:

Seem to understand what the result is the look you want, the less complex, in MYSQL environment, perform the following statement, is what you want,
The SELECT NAME1, SUM (SCORE) SCORE FROM (
SELECT a T1. *, @ RR: @ RR=+ 1 RR FROM (
SELECT T. *, @ : R=@ R + R FROM 1 (
SELECT the 'a' NAME1, '10' SCORE FROM DUAL UNION ALL
SELECT the 'a' NAME1, '20' SCORE FROM DUAL UNION ALL
SELECT 'b' NAME1, '10' SCORE FROM DUAL UNION ALL
SELECT 'b' NAME1, '30' SCORE FROM DUAL UNION ALL
SELECT 'b' NAME1, '20' SCORE FROM DUAL UNION ALL
SELECT 'b' NAME1, '30' SCORE FROM DUAL UNION ALL
SELECT the 'a' NAME1, '10' SCORE FROM DUAL UNION ALL
SELECT the 'c' NAME1, '20' SCORE FROM DUAL UNION ALL
SELECT the 'c' NAME1, '30' SCORE FROM DUAL UNION ALL
SELECT 'ding' NAME1, '10' SCORE FROM DUAL UNION ALL
SELECT 'ding' NAME1, '10' SCORE FROM DUAL UNION ALL
SELECT the 'a' NAME1, '40' SCORE FROM DUAL) T, (SELECT @ R:=0) R
T1, SELECT @ RR:=0) RR ORDER BY NAME1, R) T
GROUP BY NAME1, RR - R
The ORDER BY R.
  • Related