loading..
   English
15:01

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:

Console
Execute
  1. SELECT
  2. CASE
  3. WHEN ram < 64
  4. THEN 'W95'
  5. WHEN ram < 128
  6. THEN 'W98'
  7. ELSE 'W2k'
  8. END Type,
  9. COUNT(*) Qty
  10. FROM PC
  11. GROUP BY
  12. CASE
  13. WHEN ram < 64
  14. THEN 'W95'
  15. WHEN ram < 128
  16. THEN 'W98'
  17. ELSE 'W2k'
  18. END

As a result of running query we shall receive:

Type Qty
W2k 5
W95 3
W98 3

Here we duplicate CASE operator in SELECT clause to receive a column with the name of operational system.

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 CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema date/time functions DATEADD DATEDIFF DATENAME DATEPART DATETIME DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates EXCEPT exercise (-2) exercise 19 exercise 23 exercise 32 More tags
The book was updated
several days ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.
Rambler's Top100