Created
November 25, 2012 17:10
-
-
Save hidayat365/4144353 to your computer and use it in GitHub Desktop.
PostgreSQL Row Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- pemberian nomor baris | |
with t as ( | |
select '081011124' nim, 'IPKU1001' kode_mk, 'Agama' nama_mk, 'D' nilai union all | |
select '081011124' nim, 'IPKU1101' kode_mk, 'Pancasila' nama_mk, 'C' nilai union all | |
select '081011124' nim, 'IPKU2204' kode_mk, 'Pemrograman Java' nama_mk, 'B' nilai union all | |
select '081011124' nim, 'IPKU1101' kode_mk, 'Pancasila' nama_mk, 'B' nilai | |
) | |
select nim, kode_mk, nama_mk, nilai | |
, row_number() over(partition by kode_mk order by nilai) baris | |
from t | |
-- filter hanya row bernomor baris=1 | |
with t as ( | |
select '081011124' nim, 'IPKU1001' kode_mk, 'Agama' nama_mk, 'D' nilai union all | |
select '081011124' nim, 'IPKU1101' kode_mk, 'Pancasila' nama_mk, 'C' nilai union all | |
select '081011124' nim, 'IPKU2204' kode_mk, 'Pemrograman Java' nama_mk, 'B' nilai union all | |
select '081011124' nim, 'IPKU1101' kode_mk, 'Pancasila' nama_mk, 'B' nilai | |
) | |
select nim, kode_mk, nama_mk, nilai | |
from ( | |
select nim, kode_mk, nama_mk, nilai | |
, row_number() over(partition by kode_mk order by nilai) baris | |
from t | |
) tabel1 | |
where baris=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment