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);

CodePudding user response:

reference 1st floor qq646748739 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);



If I like me to check a few days of C value, a month of C value, over a period of time the C value, a year of C value as the change of time how to write

CodePudding user response:

Is also very simple, a little change is ok,

CodePudding user response:

reference weixin_40989661 reply: 3/f
Quote: refer to 1st floor qq646748739 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);



If I like me to check a few days of C value, a month of C value, C value over a period of time, a year of C value as the change of time how to write things

As long as the statement of the 7 to 30365 or 366,
For a period of time, such as 45 days, 7 to 45,

CodePudding user response:

Can also be written as dynamic, 7 to the count (*)
Support any number of days,

CodePudding user response:

refer to 6th floor qq646748739 response:
can also be written as dynamic, 7 to the count (*)
Support any number of days,


SELECT

Round (avg (n. "inventory surplus rate"/count (*), 2)) avgs from (select SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C))) from TZYPLUPRO T
Writing prompt parameter is invalid because my grammar is wrong?



CodePudding user response:

Just started to learn SQL?

You write the SQL there are at least the following seven questions:
1. N. "inventory surplus rate" is what east east, from which rises suddenly,,,,
2. The field name in Chinese is not recommended.
3. Avg () function using a wrong brackets
4. Round brackets in the wrong place
5. SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) not used,
6. The SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) need to provide the name of the table, the outer statement won't be able to visit
7. The count (*) can't use, need to put the inner statement, alias outer statement to use it,

CodePudding user response:

refer to the eighth floor qq646748739 response:
just began to learn SQL?

You write the SQL there are at least the following seven questions:
1. N. "inventory surplus rate" is what east east, from which rises suddenly,,,,
2. The field name in Chinese is not recommended.
3. Avg () function using a wrong brackets
4. Round brackets in the wrong place
5. SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) not used,
6. The SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) need to provide the name of the table, the outer statement won't be able to visit
7. The count (*) can't use, need to put the inner statement, outer statement use its alias,

CodePudding user response:

Please refer to the SQL statement I wrote,

CodePudding user response:

refer to the eighth floor qq646748739 response:
just began to learn SQL?

You write the SQL there are at least the following seven questions:
1. N. "inventory surplus rate" is what east east, from which rises suddenly,,,,
2. The field name in Chinese is not recommended.
3. Avg () function using a wrong brackets
4. Round brackets in the wrong place
5. SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) not used,
6. The SUM (T.Q M)/(SUM (T.P S) + SUM (T.X TPS) + SUM T.D (BPS) + SUM (T.Q C)) need to provide the name of the table, the outer statement won't be able to visit
7. The count (*) can't use, need to put the inner statement, outer statement use its alias,




nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related