1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to find product with maximum discount SQL HackerRank

Discussão em 'Outras Linguagens' iniciado por Stack, Fevereiro 2, 2021.

  1. Stack

    Stack Membro Participativo

    I'm having trouble with a SQL problem in HackerRank (so no rank or window functions) and would appreciate any tips. Noob so please be gentle.

    Product_Id Product_Name Category Price Discount Available
    1 P-1 C-5 720 10 1
    2 P-2 C-1 935 17 1
    3 P-3 C-2 588 19 1
    4 P-4 C-4 619 5 0
    5 P-5 C-1 803 16 1


    I want to know which product is on maximum discount for each category. In the case of multiple products having same maximum discount within a category, print the product with the minimum product_id.

    Sample Output

    C-1 2 17
    C-2 3 19
    C-4 4 5
    C-5 1 10


    http://sqlfiddle.com/#!18/1a492d ^I've put here what I've tried so far. I'm not sure how to get the product for the maximum discount. I also don't know how to handle if there's multiple products with the same maximum discount?

    Continue reading...

Compartilhe esta Página