Ćwiczenie 1. Jaka jest średnia cena produktów ?
select avg(UnitPrice) as Average from Products;
Sugestia: zastanów się czy nie trzeba wyniku zaokrąglić do 2 miejsc po przecinku ? Jest to jednak cena.
Ćwiczenie 2. Ile jest klientów ?
select count(customerID) from Customers;
UWAGA: funkcje agregujące nie biorą pod uwagę pustych wierszy (NULL). Z tego powodu funkcja CUNT() powinna używać kolumny, która nie może być pusta, czyli kolumna z kluczem lub znaku * jeśli tabela nie ma klucza podstawowego lub nie wiemy która to kolumna.
Ćwiczenie 3. Ile wynosi różnica pomiędzy najdroższym i najtańszym produktem ?
select max(unitPrice) - min(unitPrice) as diff from Products
Ćwiczenie 4. Ile klientów ma fax ?
select count(customerID) as ile from Customers where fax is not null;
Ćwiczenie 5. Ile jest klientów w każdym kraju ?
select count(customerID) as ile , country from Customers group by Country;
Ćwiczenie 6. Jaka jest wartość zamówień ?
select sum(unitPrice*quantity*(1-discount)) as Total from [Order Details]
