loading..
Русский    English
12:07

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)
Instead of

no

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

Console
Execute
  1. SELECT COUNT(*)
  2.    FROM Product
  3.    WHERE Maker = 'E' AND type='PC';
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(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL this could be expressed as follows:

Console
Execute
  1. SELECT COUNT(DISTINCT pc.model)
  2.    FROM Product pr
  3.    JOIN PC ON pr.model=pc.model
  4.    WHERE Maker = 'E';
which yields

1

Solve this task at SQL-EX.RU

Bookmark and Share
Tags
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
month ago
https://exchangesumo.com/obmen/ECOPAYZEUR-Skrill/ . Таиланд, Сом-там и iPad
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.