1-yechim:
SELECT billingcity, max(TotalSum) AS Total FROM (
SELECT billingcity, sum(total) AS TotalSum FROM Invoice GROUP BY billingcity);
2-yechim:
SELECT Invoice.BillingCity, SUM(Invoice.Total)
FROM Invoice
GROUP BY Invoice.BillingCity
ORDER BY SUM(Invoice.Total) DESC LIMIT 1
3-savol. Eng ko‘p pul sarflagan mijoz eng yaxshi mijoz deb e’lon qilinadi. Eng ko‘p pul sarflagan kishini qaytaradigan so‘rov yozing. Men ushbu uchta ma’lumotni bog‘lash orqali yechimni topdim: bular fakturani olish uchun hisob-faktura, hisob-faktura va mijozlar jadvallari, ammo siz buni kamroq jadvallar bilan uddalashingiz mumkin!
Savolda berilganga ko’ra eng ko’p pul sarflagan eng yaxshi customerni aniqlashimiz kerak. Buning uchun barcha sarflangan pullar TotalSpentni hisoblab yig’indisini SUM() orqali topishimiz kerak. Bunda TotalSpentga asosan ORDER BY orqali tartiblab olish zarur. Tartiblangan yozuvlarning eng birinchisini olishimiz zarur, shuning uchun LIMIT dan foydalanamiz. Javob quyidagicha bo’ladi:
Do'stlaringiz bilan baham: |