Home > database > For A/B every day to get the value of the additive on the average
For A/B every day to get the value of the additive on the average
Time:09-26
Here are two column values (day) column column B Day 1 3 6 2 days 4 7 3 days 3 8 Fourth day 7 to 10 5 day 5 7 On the sixth day 6 12 Day 4 of 6 7
To query on the first day (A/B value=C1) + 2 day (A/B value=C2) + 3 days (A/B value=C3) +... 7 days (A/B value=C7); For every row/column B to get A value C, the daily addition of C value in averaging, Note: do not list the value of A seven day together seven days/column B value together to get the value, but to every row/column B to get C values, the seven days of C value added in to the average for the great god,
CodePudding user response:
- 1. To create a test table, add data The create table TMP as Select 1 dtime, 3 A, 6 B from dual union all Select 2 dtime, 4 A, 7 B from dual union all Select 3 dtime, 3 A, 8 B from dual union all Select 4 dtime, 7 A, 10 B from dual union all Select 5 dtime, 5 A, 7 B from dual union all Select 6 dtime, 6 A, 12 B from dual union all The select 7 dtime, 4 A, 6 B from dual;
- 2. Calculate average 7 days, the result 2 decimal places Select round (avg (c1/7), 2) avgs from (select sum (a/b) avgs from TMP);
CodePudding user response:
What is the meaning of SQL
- 1.7 days average addition Select sum (a/b) avgs from TMP.
- 2. Calculate the mean average Select round (avg (c1/7), 2) avgs from (select sum (a/b) avgs from TMP);