Exercise #24 page 1 |
|||||
Find the model number of the product (PC, laptop, or printer) with the highest price.Result set: model Below is erroneous solution that has been admitted by site's checking system some time ago. Solution 1.16.1
I suggest to clear up what data must be in the test database to block such solutions. So, what does this query do? In each of three similar subqueries models from three types of products - PC, PC-laptop or printer - are selected by maximum price. Then UNION is used to combine the found models and besides to remove duplicated rows {model, price}. At last, the models having the same price as the maximum price for PC-laptops are left. So if the maximum price over all products coincides with the maximum price on printers this solution will be rejected by the system. But then a solution having
Solution 1.16.2
Conclusion. Whatever the data may be, with the help of the first query the solution can be adjusted in three attempts, in the worst case. The second solution won't pass at all, if the maximum is reached for at least two types of products. But then for adjusting the first solution we'll need only two attempts. If in every type of product there is a model with the same maximum price, one try will be enough. By the way, the data is picked up optimally for the examined cases, but, anyway, it doesn't prevent from the wrong queries' passage. Way out of this situation, and not only this, can be found in increasing the amount of test databases, where different data variants will be simulated. The only thing that prevents me from doing this is slowing down the system's work, which will cause the user to spend more time waiting. I also comfort myself by a thought that our visitors' motivation is SQL study and qualification improvement but not a tendency to fool the system.
|