Blog gw

sql untuk mencari nilai terbesar dari masing2 pengelompokan

Posted by dillah2008 on March 24, 2008

Hari ini dapat masalah yang sebenernya sudah pernah gw liat solusinya waktu dulu, tapi memang karena pikun jadinya lupa lagi..untung si pohan bs membantu…hehehehe,thanks bos ;)

Semisal ada table namanya a
id         cust_code
—————
1               001
2               001
3               001
4               001
5               002
6               002
7               003
8               003

Dari table tersebut gw mau menghasilkan id terbesar dari tiap2 cust_code tersebut, seperti berikut:
id            cust_code
——————-
4                001
6                002
8                003

Maka SQL nya kurang lebih seperti ini :
select cust_code,max(id) as id from a group by cust_code order by cust_code

Sebenernya ini dasar sekali tapi tadi ketika diperlukan tidak tahu harus bagaimana ..hehehehe :”>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>