Question is this: now want to achieve from under A pile of data, A random sample of four categories: A, B, C, D make the last val A total of 960
Data table has two columns in A
The type, val
D 11
9 C
30 D
D 20
21 C
14 C
17 B
A 16
9 B
19 B
13 D
A 8
9 B
30 B
A 12
A 6
30 B
13 B
14 C
B 16
5 B
30 C
30 B
15 D
30 B
30 B
9 B
13 B
D 57
15 D
23 D
10 B
13 D
17 B
15 B
A 15
16 C
13 D
19 D
5 B
8 C
17 B
A 6
5 B
D 12
17 B
11 C
17 B
A 24
11 B
19 B
A 9
15 D
28 C
D 32
D 10
15 C
A 12
19 D
30 B
B 16
13 D
11 B
30 D
CodePudding user response:
A random sample of four categories: A, B, C, D, make the last val value of 960 - didn't understand, A, B, C, D4 types, each type of at least one, the total number, but the total is 960?
CodePudding user response:
reference 1st floor ZBDZJX response: A random sample of four categories: A, B, C, D, make the last val value of 960 - didn't understand, A, B, C, D4 types, each type of at least one, the total number, but the total is 960? Means four species, random sampling, no matter how, finally sum to 960. Probably A, B, C, D, there are one or two is empty CodePudding user response:
Don't understand ~ ~ The end result is what? A, B, C, D, or any combination of them? But to ask the result is 960? According to A, B, C, D respectively summary Select the type, the sum (val) from table A group by type. Then, see how each value of the type of combination into 960? CodePudding user response:
Requirements regarding this topic, you condition is too little, also too little: With s As ( - the value category [1 times] summarizing the category value smoke [2] summary the category smoke [3] summary Select the type, the sum (distinct val) as s1, the sum (distinct val) * 2 as s2, sum (distinct val) * 3 as s3 The from t Group by type The order by type ) - all categories combined smoke [3] [1 times] smoke [3] Select 'SUMV' as the type, the sum (s1), sum (s2), sum (s3) The from s Union all Select * The from s The order by 1 CodePudding user response:
This algorithm is, not ORACLE can solve easily CodePudding user response:
The reference 4 floor jinsenhome reply: this topic, you condition is too little, requirement also too little: With s As ( - the value category [1 times] summarizing the category value smoke [2] summary the category smoke [3] summary Select the type, the sum (distinct val) as s1, the sum (distinct val) * 2 as s2, sum (distinct val) * 3 as s3 The from t Group by type The order by type ) - all categories combined smoke [3] [1 times] smoke [3] Select 'SUMV' as the type, the sum (s1), sum (s2), sum (s3) The from s Union all Select * The from s The order by 1 That is to say, you are the 960, must be allowed to smoke a category 2 +, If so, you this wasn't actually SQL implementation, oneself write a program, select from val pool, ensure {4} 2 types of values, smoking many times no matter (of course, you can also limit the most times, for example 5) get 960! CodePudding user response:
refer to 6th floor jinsenhome response: Quote: refer to 4th floor jinsenhome response: Requirements regarding this topic, you condition is too little, also too little: With s As ( - the value category [1 times] summarizing the category value smoke [2] summary the category smoke [3] summary Select the type, the sum (distinct val) as s1, the sum (distinct val) * 2 as s2, sum (distinct val) * 3 as s3 The from t Group by type The order by type ) - all categories combined smoke [3] [1 times] smoke [3] Select 'SUMV' as the type, the sum (s1), sum (s2), sum (s3) The from s Union all Select * The from s The order by 1 That is to say, you are the 960, must be allowed to smoke a category 2 +, If so, you this wasn't actually SQL implementation, oneself write a program, select from val pool, ensure {4} 2 types of values, smoking many times no matter (of course, you can also limit the most times, for example 5) get 960! This topic is consider very fear, similar to the smart deduction, like playing chess!!!!!! CodePudding user response:
Write a stored procedure inside slowly to judge?