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
Many users point out a "mistake" in the reference query. Complaints basically boil down to the following query 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:
|