Asosiy matnga o'tish

121. Qator taqqoslash (a, b) = (...)

Qiyin

Avval eng katta summali bitta sotuvni toping. So'ng o'sha sotuv bilan

bir xil (shahar, mahsulot) juftligiga ega barcha sotuvlarni chiqaring

(eng kattasining o'zi ham kiradi).

Buni qator konstruktori bilan yozing:

WHERE (city, product) = (SELECT city, product FROM ... ORDER BY ... LIMIT 1)

Ikkita ustunni ikkita alohida ichki so'rov bilan emas, bitta ichki so'rov

bilan taqqoslash shu usulning mohiyati.

Ustunlar: id, city, product, amount.

Saralash: amount kamayish, keyin id o'sish.

sales: id INT PK, city VARCHAR, product VARCHAR, amount NUMERIC(12,2)

Jadval: sales

UstunTuri
idINT PK
cityVARCHAR(40)
productVARCHAR(40)
amountNUMERIC(12,2)

Namuna ma'lumotlar

sample
sales
idINTcityVARCHAR(40)productVARCHAR(40)amountNUMERIC(12,2)
4SamarqandNoutbuk8700000
9SamarqandNoutbuk1500000
5SamarqandSmartfon3100000
6BuxoroNoutbuk5600000
Kutilgan natija
idcityamountproduct
4Samarqand8700000Noutbuk
9Samarqand1500000Noutbuk
sample-full
sales
idINTcityVARCHAR(40)productVARCHAR(40)amountNUMERIC(12,2)
1ToshkentNoutbuk9800000
2ToshkentNoutbuk4200000
3ToshkentSmartfon3900000
4SamarqandNoutbuk8700000
5SamarqandSmartfon3100000
6BuxoroNoutbuk5600000
7ToshkentNoutbuk7300000
8BuxoroSmartfon2800000
9SamarqandNoutbuk1500000
10AndijonMuzlatgich6400000
11ToshkentMuzlatgich5200000
12ToshkentNoutbuk1100000
13NamanganSmartfon3300000
14BuxoroNoutbuk2700000
Kutilgan natija
idcityamountproduct
1Toshkent9800000Noutbuk
7Toshkent7300000Noutbuk
2Toshkent4200000Noutbuk
12Toshkent1100000Noutbuk
sample-extra
sales
idINTcityVARCHAR(40)productVARCHAR(40)amountNUMERIC(12,2)
1SamarqandSmartfon4474600
2ToshkentSmartfon1100000
3ToshkentSmartfon3751400
4SamarqandNoutbuk8339100
5BuxoroMuzlatgich4235100
6BuxoroMuzlatgich7454304.4
7BuxoroNoutbuk1500000
8SamarqandNoutbuk5600000
9ToshkentNoutbuk3004700
10ToshkentNoutbuk10926300
Kutilgan natija
idcityamountproduct
10Toshkent10926300Noutbuk
9Toshkent3004700Noutbuk

O'xshash masalalar

Konsol

Natijani ko'rish uchun so'rovni ishga tushiring.