question : select distinct and sum sql syntax

hi inkubis,…

thanks for reading my message. Below is the table structure and sample data.

CODE AMOUNT
aaa 100
ccc 200
bbb 50
bbb 100
aaa 150
aaa 100

I would like to know how i can select distinct and sum at the same time from the above sample data ? I am using “SELECT DISTINCT CODE,SUM(AMOUNT) FROM TABLE” as the query but it is not accepted. Thanks in advance. Best regards.


owala maksud dari pertanyaannya itu adalah gimana cara menggabungkan dan menjumlah dari tabel diatas. jadi yang code di gabung yang sama (dsitinct) trus yang amount di jumlah berdasarkan code yang sama.

with your problem, we can solve with nested select, which select in your select.

select distinct code, (select sum(amount) from nametable as nestedtable where nestedtable.code=nametable.code) from nametable

result;
aaa  —– 350
bbb —– 150
ccc  —– 200