HAVING clause |
||
Let's determine only red squares, i.e. squares which were painted with only red spray cans, and total quantity of red-color paint equals 255 on each of these squares. We consider Painting database. This problem can be solved by a number of ways. Here we'll use CASE operator in HAVING clause. Here is idea. Let's group the paintings by square id while summing quantity of paint. In so doing red-color paint will be added to the sum with sign "+" whereas other paints - with sign "-". In view of the fact that the volume of any paint must not exceed 255, the result that equals 255 exactly says to us that all paint is of red color and no other color paint was used. Here is the solution:
|