A count for each grouping rather than the full table : GROUP BY « Query « SQL Server / T-SQL Tutorial






6> CREATE TABLE Employees (
7>      EmployeeID int NOT NULL ,
8>      LastName nvarchar (20) NOT NULL ,
9>      FirstName nvarchar (10) NOT NULL ,
10>     Title nvarchar (30) NULL ,
11>     TitleOfCourtesy nvarchar (25) NULL ,
12>     BirthDate datetime NULL ,
13>     HireDate datetime NULL ,
14>     Address nvarchar (60) NULL ,
15>     City nvarchar (15) NULL ,
16>     Region nvarchar (15) NULL ,
17>     PostalCode nvarchar (10) NULL ,
18>     Country nvarchar (15) NULL ,
19>     HomePhone nvarchar (24) NULL ,
20>     Extension nvarchar (4) NULL ,
21>     Photo image NULL ,
22>     Notes ntext NULL ,
23>     ReportsTo int NULL ,
24>     PhotoPath nvarchar (255) NULL
25>
26> )
27> GO

1>
2>    SELECT ReportsTo, COUNT(*)
3>    FROM Employees
4>    GROUP BY ReportsTo
5> GO
ReportsTo
----------- -----------

(0 rows affected)
1>
2> drop table Employees;
3> GO








1.4.GROUP BY
1.4.1.A summary query that counts the number of Billings by Banker
1.4.2.Group by and table join
1.4.3.A summary query with a search condition in the WHERE clause
1.4.4.Extracting partial records using GROUP BY.
1.4.5.GROUP BY with SUM()
1.4.6.both the EmployeeID and CustomerID columns in our GROUP BY
1.4.7.A count for each grouping rather than the full table
1.4.8.Using GROUP BY ALL