GROUP BY clause
Let's now receive the number of the computers those RAM-suitable to each type of operational system. Then we can write the following query:
As a result of running query we shall receive:
Here we duplicate CASE operator in SELECT clause to receive a column with the name of operational system.
You can do the grouping by different number of columns using CASE operator within a single query. Let's consider the following task for example.
For each unique pair of values of processor's speed and hd capacity, determine average PC price. For the products with speed lower than $600, do grouping by a speed only.
For comparison, first let's obtain grouping by one column (speed) and by two columns (speed, hd) respectively.
Here each group has the same values in hd column, so max(hd) can be used instead of hd and vice versa.
Now is the solution of the problem:
When the condition speed >= 600 is true, the grouping is using the speed, hd columns, otherwise the grouping turns into
Though the explicit grouping - GROUP BY speed, NULL - gives an error.