Exercise 3 (rating)

For the Product table, get a result set consisting of the following columns: maker, pc, laptop, and printer.
 For each maker, it should be indicated whether he manufactures  goods of a certain type (if so, the corresponding column should contain “yes”), or not (“no”).
 In the first case, “yes” should be directly followed (without any spaces) by the number of distinct models of the corresponding product type offered for sale (that is, present in the PC, Laptop, or Printer table) enclosed in parentheses.

 If the manufacturer has models of some type in the Product table, but none of them is offered for sale, then, according to the task formulation, the result should be

yes(0)
no

Many users point out a “mistake” in the reference query. Complaints basically boil down to the following query

SELECT COUNT(*)
   FROM Product
  
WHERE Maker = 'E' AND type='PC';
mssql
🚫
[[ error ]]
[[ column ]]
[[ value ]]
returning three PC models for manufacturer Е, while the “correct answer” claims this maker produces only one computer model. Let’s have another look at the task formulation that tells us:

“…“yes” should be directly followed (without any spaces) by the number of distinct models of the corresponding product type offered for sale (that is, present in the PC, Laptop, or Printer table) enclosed in parentheses.“

In our case, this means the number of distinct computer models by maker E present in the PC table has to be displayed in parentheses. In terms of SQL this could be expressed as follows:

SELECT COUNT(DISTINCT pc.model)
   FROM Product pr
   JOIN PC ON pr.model=pc.model
   WHERE Maker = 'E';
mssql
🚫
[[ error ]]
[[ column ]]
[[ value ]]
which yields

1

Solve this task at SQL-EX.RU