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
4 Responses to “question : select distinct and sum sql syntax”
Leave a Reply






mirza on September 24th, 2009
Wewh, mantab jaya jawabane……
Girls on November 6th, 2009
gw coba dengan kasus serupa tapi ko gagal ya? pada kasus ini menjumlah AMOUNT yg disaring melalui CODE. pada kasus saya, saya menjumlah SKS yg disaring melalui NPM dan KD_MK. bisa tolong dibantu?
Admin on November 7th, 2009
@girls : boleh tau tabelnya kayak apa, trus datanya apa saja. boleh dikirim di email
inkubis@ymail.com
Ocim on December 19th, 2009
duh.. gw jg dicoba ga bisa kenapa yaaa.
bener ga sih kalo gw cobanya di sql trus gw tulis di formulanya…..??