SQL 2008 Essentials

Page 283

268

CHAPTER 9

NULL 1 2 3 NULL 2 3 4 NULL 1 2 4 NULL 1

Aggregation and GROUP BY

ENGL ENGL ENGL ENGL MATH MATH MATH MATH POLY POLY POLY POLY UNKN UNKN

1 3 2 4 2 3 1 1 2 3 2 1 1 1

(24 row(s) affected) The sequence of the columns in a GROUP BY clause has the eямАect of ordering the output. If we change the order of the GROUP BY, like this: SELECT class, major, COUNT(*) AS [count] FROM Student GROUP BY major, class Our result will look like this: class -----NULL NULL NULL NULL NULL NULL 1 1 1 1 2 2 2 2 2 3

major ----NULL COSC ENGL MATH POLY UNKN COSC ENGL POLY UNKN ACCT COSC ENGL MATH POLY ART

count ----------3 1 1 2 2 1 4 3 3 1 1 2 2 3 2 1


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.