Home > database >  SQL the difference in the amount in accordance with the income proportion to tail difference how to
SQL the difference in the amount in accordance with the income proportion to tail difference how to

Time:10-23

Now have the following data
The line number income
1 1111
2 2222
3 3333
4 4444
5 5555
6 6666
Total 23331

Existing differences in 500, and then calculating the coefficient divided by the total revenue and the difference amount get income amount * coefficient, the results to keep the two, the difference between total 0.01 more than the actual and the 0.01 please change how to deal with, how to allocate to the last line, through the way of statement
Line number income contribution factor contribution amount
1, 1111, 0.021430715, 23.81
2 2222 0.021430715 47.62
3 3333 0.021430715 71.43
4 4444 0.021430715 95.24
5 5555 0.021430715 119.05
6 6666 0.021430715 142.86
Total 23331 500.01

CodePudding user response:

What do you mean share amount and and the difference value of difference to the last line number on the contributions of?

CodePudding user response:

The update directly, grab the largest amount the ROWID, conditions for the update

CodePudding user response:

First want to know the difference between the data on which a record of processing, is one of the largest, and so on line number or amount of the largest, think good the rules of good processing,
On the last line of your plan to deal with, for example, the first article 5 the amount of data in front of the summary, and then use a total of 500 got the last one to reduce aggregate amount data
The contribution amount,

CodePudding user response:

I want to use row_number () over function, but how can I get the largest line number, biggest line may have the same

CodePudding user response:

And rank and dense_rank

CodePudding user response:

Row_number () over a sort of serial number, over () can be used inside the order desc sorting, then take sort of first line
reference 4 floor qq_29728233 response:
I want to use row_number () over function, but how can I get the largest line number, biggest line may have the same

CodePudding user response:

You mean the results returned by the SQL, than the correct values, deviation is 0.01, isn't it,
If so, please save digital field types in the database, whether amount, or the other, as long as deposit digital field types, all with a DECIMAL type,

CodePudding user response:

reference 1st floor lich2005 response:
first to want to know the difference of data processing in which a record, is one of the largest, and so on line number or amount of the largest, think good the rules of good processing,
On the last line of your plan to deal with, for example, the first article 5 the amount of data in front of the summary, and then use a total of 500 got the last one to reduce aggregate amount data
The contribution amount,

Is to say, please put your horse

CodePudding user response:

A total of N lines, the value of the last line, for 500 - the SUM (N1 + N2 +,,,, N (N - 1))
  • Related