mySQL - ustunlar jami

Menda 2 ta jadval bor

1-jadval

id product
1  P1
2  P2

2-jadval

id amount product_t1
1  100    P1
2  200    P1
3  300    P2
4  400    P1
5  500    P2

Mening chiqqani bo'lishini xohlayman:

product totalAmount(sum of amount)
P1      700
P2      800

EDIT: Mana, hozirgi so'rovim

SELECT T1.product, SUM(T2.amount)
FROM table1 T1
INNER JOIN table2 T2
ON T1.product = T2.product_t1

Rahmat!

1
Hozirgacha nimalarga erishilgan?
qo'shib qo'ydi muallif Stefano Zanini, manba
Hozirgacha nimalarga erishilgan?
qo'shib qo'ydi muallif Stefano Zanini, manba
Afsuski, hozir u erda. Men P1 15000ni olaman
qo'shib qo'ydi muallif Maki, manba
Afsuski, hozir u erda. Men P1 15000ni olaman
qo'shib qo'ydi muallif Maki, manba

7 javoblar

 SELECT T1.product, SUM(T2.amount)
 FROM table1 T1
 INNER JOIN table2 T2
 ON T1.product = T2.product_t1
 GROUP BY product T1.product

GROUP BY yorlig'ini ishlating. Guruh tomonidan sizning mahsulotingizni mahsulot bahosiga ko'ra guruhlashingiz mumkin

1
qo'shib qo'ydi
 SELECT T1.product, SUM(T2.amount)
 FROM table1 T1
 INNER JOIN table2 T2
 ON T1.product = T2.product_t1
 GROUP BY product T1.product

GROUP BY yorlig'ini ishlating. Guruh tomonidan sizning mahsulotingizni mahsulot bahosiga ko'ra guruhlashingiz mumkin

1
qo'shib qo'ydi

Chet el kalitlarini ishlatmaysiz, shuning uchun kerakli natijalar uchun tab-1 kerak emas.

SELECT
    product_t1 AS product,
    SUM(amount) AS totalAmount
FROM table2
GROUP BY product_t1

Siz kam bo'lgan narsa GROUP BY - har bir mahsulot uchun alohida satrni olish uchun

1
qo'shib qo'ydi
SELECT T1.product, jami (T2.amount) FROM jadval1 T1 INNER JOIN table2 T2 ON T1.product = T2.product_t1 Gruop by T1.product
qo'shib qo'ydi muallif Michael, manba
Men chet el kalitini T1.product = T2.product_t1 dan foydalanmoqdaman. T1 mahsuloti noyobdir
qo'shib qo'ydi muallif Maki, manba

Chet el kalitlarini ishlatmaysiz, shuning uchun kerakli natijalar uchun tab-1 kerak emas.

SELECT
    product_t1 AS product,
    SUM(amount) AS totalAmount
FROM table2
GROUP BY product_t1

Siz kam bo'lgan narsa GROUP BY - har bir mahsulot uchun alohida satrni olish uchun

1
qo'shib qo'ydi
SELECT T1.product, jami (T2.amount) FROM jadval1 T1 INNER JOIN table2 T2 ON T1.product = T2.product_t1 Gruop by T1.product
qo'shib qo'ydi muallif Michael, manba
Men chet el kalitini T1.product = T2.product_t1 dan foydalanmoqdaman. T1 mahsuloti noyobdir
qo'shib qo'ydi muallif Maki, manba

guruhni qo'llash kerak

 SELECT T1.product, SUM(T2.amount)
 FROM table1 T1
 INNER JOIN table2 T2
 ON T1.product = T2.product_t1
 GROUP BY product
1
qo'shib qo'ydi

Try to play with GROUP BY and AS

 SELECT product_t1 as product, SUM(amount) AS totalAmount FROM table2
 GROUP BY product

https://dev.mysql.com /doc/refman/5.7/en/group-by-modifiers.html

YoKI kod guruhiga qo'shing

 SELECT T1.product, SUM(T2.amount) 
 FROM table1 T1 
 INNER JOIN table2 T2 ONT1.product = T2.product_t1 

 Gruop by T1.product
0
qo'shib qo'ydi

Try to play with GROUP BY and AS

 SELECT product_t1 as product, SUM(amount) AS totalAmount FROM table2
 GROUP BY product

https://dev.mysql.com /doc/refman/5.7/en/group-by-modifiers.html

YoKI kod guruhiga qo'shing

 SELECT T1.product, SUM(T2.amount) 
 FROM table1 T1 
 INNER JOIN table2 T2 ONT1.product = T2.product_t1 

 Gruop by T1.product
0
qo'shib qo'ydi