1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
rodikova [14]
2 years ago
9

A department store maintains data on customers, products, and purchase records in three tables: customer, product, and purchase.

the store manager wants to know which product is on maximum discount for each category. write a query to print the following fields for each category, ordered by category, ascending: category, product id and discount for the product that has the maximum discount in the category. in the case of multiple products having same maximum discount within a category, print the product with minimum product_id.
Computers and Technology
1 answer:
saw5 [17]2 years ago
8 0
<h3>The maximum discount using SQL</h3>

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

<h3>The Output </h3>

C-1 2 17

C-2 3 19

C-4 4 5

C-5 1 10

The code that would print the fields in SQL for the maximum discount is:

WITH newTable AS (

SELECT

t.Category,

t.Product_Id,

b.Discount as maxDiscount,  

ROW_NUMBER() OVER (

                        PARTITION BY t.Category

                        ORDER BY Product_Id DESC

                  ) AS [ROW NUMBER]

FROM Products t

INNER JOIN

(

 SELECT MAX(Discount) as maxDiscount, Category

 FROM Products

GROUP BY Category

) b ON t.Discount = b.Discount AND t.Category = b.Category)

select Category,Product_Id,maxDiscount from newTable

WHERE newTable.[ROW NUMBER] = 1

Read more about SQL here:

brainly.com/question/25694408

#SPJ1

You might be interested in
Tricia listed her assets and liabilities. Credit Card Bill Car Loan Bonds Piano Bank Account Bicycle Which are Tricia’s liabilit
DIA [1.3K]
<span>Her liabilities are her credit card bill and her car loan. These are things that she owes and has to pay off, so they are liabilities due to the fact that she owes for these items. Her bonds, piano, bank account, and bicycle are counted as assets.</span>
7 0
3 years ago
Read 2 more answers
The excessive use of the internet and the web for personal use at work is sometimes called ____ .
Elodia [21]
This is called Cyberslacking
7 0
3 years ago
Read 2 more answers
State one advantage of organising data into columns and rows
Bezzdna [24]
It's neat organized and ready to find when needed
6 0
3 years ago
On an XBOX 360, what does it mean if you get 4 red rings on your console?
Hitman42 [59]

Answer:

C. This happened to me.

Explanation:

4 0
3 years ago
Write a program that first calls a function to calculate the square roots of all numbers from 1 to 1,000,000 and write them to a
svlad2 [7]

Answer:

The csharp program to compute square roots of numbers and write to a file is as follows.

class Program  

{  

static long max = 1000000;  

static void writeRoots()  

{  

StreamWriter writer1 = new StreamWriter("roots.txt");  

double root;  

for (int n=1; n<=max; n++)  

{  

root = Math.Sqrt(n);  

writer1.WriteLine(root);  

}  

}  

static void Main(string[] args)  

{  

writeRoots();  

}  

}

The program to compute squares of numbers and write to a file is as follows.

class Program  

{  

static long max = 1000000;  

static void writeSquares()  

{  

StreamWriter writer2 = new StreamWriter("squares.txt");  

long root;  

for (int n = 1; n <= max; n++)  

{  

root = n*n;  

writer2.WriteLine(root);  

}  

}  

static void Main(string[] args)  

{  

writeSquares();  

}  

}  

Explanation:

1. An integer variable, max, is declared to hold the maximum value to compute square root and square.

2. Inside writeRoots() method, an object of StreamWriter() class is created which takes the name of the file as parameter.

StreamWriter writer1 = new StreamWriter("roots.txt");

3. Inside a for loop, the square roots of numbers from 1 to the value of variable, max, is computed and written to the file, roots.txt.

4. Similarly, inside the method, writeSquares(), an object of StreamWriter() class is created which takes the name of the file as parameter.

StreamWriter writer2 = new StreamWriter("squares.txt");

5. Inside a for loop, the square of numbers from 1 to the value of the variables, max, is computed and written to the file, squares.txt.

6. Both the methods are declared static.

7. Inside main(), the method writeRoots() and writeSquares() are called in their respective programs.

8. Both the programs are written using csharp in visual studio. The program can be tested for any operation on the numbers.

9. If the file by the given name does not exists, StreamWriter creates a new file having the given name and then writes to the file using WriteLine() method.

10. The csharp language is purely object-oriented language and hence all the code is written inside a class.

3 0
3 years ago
Other questions:
  • How does the occupational outlook affect the monetary benefits of a career
    11·1 answer
  • Does learning swift is hard? more than android?
    13·1 answer
  • Which of the following functions does a browser perform?
    7·2 answers
  • Write a program that reads a stream of integers from a file and writes only the positive numbers to a second file. The user shou
    5·1 answer
  • Give an O(log m + log n)-time algorithm that takes two sorted lists of sizes m and n, respectively, as input and returns the ith
    7·1 answer
  • How does the use of the computer impact businesses
    13·1 answer
  • Select the correct answer.
    10·1 answer
  • 1.
    13·1 answer
  • What are two advantages of a pay-for-use online conferencing service compared to a free service? (Choose two)
    5·1 answer
  • Answer the following question in 3-4 complete sentences. Define the following terms: - registration - press - keyblock.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!