SQL Puzzles (father's stamps)

Source: Internet
Author: User
Tags rtrim

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.