Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

1

© BELGIUM CAMPUS 2021


2

© BELGIUM CAMPUS 2021


3

© BELGIUM CAMPUS 2021


4

The optional GROUP BY clause combines into a single record all records
that have identical values in a particular field or combination of fields.

SELECT store_name , SUM(Sales)

FROM store_information

GROUP BY store_name
5

SELECT COUNT(EmployeeID) AS ‘Number of Employees’, City


FROM Employees
GROUP BY City

SELECT SUM(UnitPrice*Quantity), OrderID


FROM [Order Details]
GROUP BY OrderID

SELECT COUNT(OrderID), ShipCity, ShipRegion, ShipCountry


FROM Orders
GROUP BY ShipCity, ShipRegion, ShipCountry
6

SELECT store_name , SUM(Sales)

FROM store_information

GROUP BY store_name

HAVING SUM(Sales) > 1500


7

SELECT COUNT(EmployeeID) AS ‘Number of Employees’, City


FROM Employees
WHERE City IN (‘Pretoria’, ‘Cape Town’, ‘Durban’, ‘Johannesburg’)
GROUP BY City
HAVING COUNT(EmployeeID) >3

SELECT SUM(UnitPrice*Quantity), OrderID


FROM [Order Details]
GROUP BY OrderID
HAVING SUM(UnitPrice*Quantity) BETWEEN 200 AND 1500

SELECT COUNT(OrderID), ShipCity, ShipRegion, ShipCountry


FROM Orders
GROUP BY ShipCity, ShipRegion, ShipCountry
HAVING COUNT(OrderID) < 200
ORDER BY COUNT(OrderID) ASC
8

Complete Retrieving Data Exercise 2. You


have 15 Minutes.

© BELGIUM CAMPUS 2021

You might also like