Exercices
Ushtrim 1
Te afishojme per cdo punonjes sa ka qene numri i porosive qe ka trajtuar si me poshte:
zgjidhje
select
e.EmployeeID as kodi,
e.FirstName as Emri,
e.LastName as Mbiemri,
count(OrderID) as Porosi
from Orders o join Employees e
on o.EmployeeID=e.EmployeeID
group by e.EmployeeID,e.FirstName,e.LastName
Ushtrim 2
Te afishojme per cdo kompani klient ( emri i kompanise) sa ka qene numri i porosive qe ka bere si me poshte:
Kodi
ALFKI
Klienti
Albanian Finance Group
Porosi
100
zgjidhje
select c.CustomerID as Kodi,
c.CompanyName as Klienti,
COUNT(o.OrderID) as Porosi
from
Orders o join customers c
on o.CustomerID=c.CustomerID
group by c.CustomerID,c.CompanyName
Ushtrim 3
Per cdo kategori produkti afishoni kodin, emrin e kategorise dhe numrin e llojeve te produkteve qe ka ajo kategori.
Kodi
1
Emertimi
Beverages
Produkte
15
Zgjidhje
select c.CategoryID as kodi,
c.CategoryName as emertimi,
count(ProductID) as produkte
from Products p join Categories c
on p.CategoryID=c.CategoryID
group by c.CategoryID,c.CategoryName
Ushtrim 4
Per cdo kategori produkti afishoni kodin, emrin e kategorise dhe cmimi mesatar te produkteve qe ka ajo kategori.
Kodi
1
Emertimi
Beverages
Cmimi mesatar
15.12
zgjidhje
select c.CategoryID,
c.CategoryName,
avg(UnitPrice) as Cmimimesatar
from Products p join Categories c
on p.CategoryID=c.CategoryID
group by c.CategoryID,c.CategoryName
Ushtrim 5
Per cdo kategori produkti afishoni kodin, emrin e kategorise, numrin e llojeve te produkteve dhe cmimin mesatar te produkteve qe ka ajo kategori.
Zgjidhje
select c.CategoryID,
c.CategoryName,
COUNT(p.ProductID) as produkte,
avg(UnitPrice) as Cmimimesatar
from Products p join Categories c
on p.CategoryID=c.CategoryID
group by c.CategoryID,c.CategoryName
Ushtrim 6
Per cdo kategori produkti afishoni kodin, emrin e kategorise, numrin e llojeve te produkteve dhe cmimin mesatar te produkteve qe ka ajo kategori dhe sasine ne stok per te gjithe produktet e kategorise
Zgjidhje
select c.CategoryID,
c.CategoryName,
COUNT(p.ProductID) as produkte,
avg(UnitPrice) as Cmimimesatar,
SUM(UnitsInStock) as Gjendje
from Products p join Categories c
on p.CategoryID=c.CategoryID
group by c.CategoryID,c.CategoryName
Ushtrim 7
Per cdo kategori produkti afishoni kodin, emrin e kategorise, numrin e llojeve te produkteve dhe cmimin mesatar, minimal, maksimal te produkteve qe ka ajo kategori dhe sasine ne stok per te gjithe produktet e kategorise
Zgjidhje
select c.CategoryID,
c.CategoryName,
COUNT(p.ProductID) as produkte,
avg(UnitPrice) as Cmimimesatar,
MIN(Unitprice) as CmimiMin,
MAX(UnitPrice) as CmimiMax,
SUM(UnitsInStock) as Gjendje
from Products p join Categories c
on p.CategoryID=c.CategoryID
group by c.CategoryID,c.CategoryName