1-laboratoriya topshirig’i



Download 29,44 Kb.
bet11/11
Sana13.01.2022
Hajmi29,44 Kb.
#355641
1   2   3   4   5   6   7   8   9   10   11
Bog'liq
2 5330464480633557121

1-yechim:

WITH tab1 AS

(

SELECT c.CustomerId, c.FirstName, c.LastName, c.Country, SUM(i.Total) TotalSpent



FROM Customer c

JOIN Invoice i ON c.CustomerId = i.CustomerId

GROUP BY c.CustomerId

)

SELECT tab1.*



FROM tab1

JOIN


(

SELECT CustomerId, FirstName, LastName, Country, MAX(TotalSpent) AS TotalSpent

FROM tab1

GROUP BY Country

) tab2

ON tab1.Country = tab2.Country



WHERE tab1.TotalSpent = tab2.TotalSpent

ORDER BY Country;



2-yechim:

WITH t1 AS

(

SELECT Customer.Country, SUM(Invoice.Total) TotalSpent, Customer.FirstName,



Customer.LastName, Customer.CustomerId

FROM Customer

JOIN Invoice ON Customer.CustomerId = Invoice.CustomerId

GROUP BY Customer.CustomerId

)

SELECT t1.CustomerId, t1.FirstName, t1.LastName, t1.Country, t1.TotalSpent



FROM t1

INNER JOIN (

SELECT t1.Country, MAX(t1.TotalSpent) as max_ts FROM t1 GROUP BY Country) AS t2

ON t1.Country=t2.Country



WHERE t1.TotalSpent=t2.max_ts

ORDER BY t1.Country
Download 29,44 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   11




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish