Question: Father needs 1 points, 2 points, 3 points, 5 points, 10 points of stamps, two of them buy four, the other three kinds of each buy three Zhang I forget what kind of? He gave me some 10 cents, just to buy the stamps.
Calculation and Analysis process:
--Through the limit algorithm, if all is 3, the minimum value is 63, if all 4, then the maximum is 84, and can be divisible by 10, then 70 and 80
1) between (1+2+3+5+10) (1+2+3+5+10)
2) x/10= integer
CREATE TABLE# (VALINT)INSERT into #SELECT 1 UNION AllSELECT 2 UNION AllSELECT 3 UNION AllSELECT 5 UNION AllSELECT Ten CREATE TABLE#2(VALINT)INSERT into#2SELECT 4 UNION AllSELECT 3 withCte as(SELECT#. VAL val,#2. VAL VAL1 from#JOIN#2 on 1=1)SELECT RTRIM(C1. VAL1)+'Zhang'+RTRIM(C1. VAL)+'points,'+RTRIM(C2. VAL1)+'Zhang'+RTRIM(C2. VAL)+'points,'+RTRIM(C3. VAL1)+'Zhang'+RTRIM(C3. VAL)+'points,'+RTRIM(C4. VAL1)+'Zhang'+RTRIM(C4. VAL)+'points,'+RTRIM(C5. VAL1)+'Zhang'+RTRIM(C5. VAL)+'points'Result fromCTE c1,cte c2,cte c3,cte c4,cte C5WHEREC1. VAL1+C2. VAL1++C3. VAL1++C4. VAL1++C5. VAL1= - andC1. VAL=1 andC2. VAL=2 andC3. VAL=3 andC4. VAL=5 andC5. VAL=Ten andC1. VAL1*C1. VAL+C2. VAL1*C2. VAL+C3. VAL1*C3. VAL+C4. VAL1*C4. VAL+C5. VAL1*C5. VALinch( -, the)
Execution Result:
SQL Puzzles (father's stamps)