database - SELECT field GROUP BY max(field) and GROUP BY other field MySQL -


i have record pic, please click show pic

how pic, please click show pic

create table query:

create table lap ( no_faktur varchar(30) primary key, tgl_jual date, kd_barang varchar(20), nm_barang varchar(100), harga_beli int (20), harga_jual int(20), jum_jual int(10) );

insert table query:

insert lap values ('fj-2013001','2013-10-01','b-001','laptop apple','500000','700000','2'); insert lap values ('fj-2013002','2012-10-01','b-002','laptop apple','300000','500000','4'); insert lap values ('fj-2013003','2013-10-03','b-001','laptop apple','500000','700000','1'); insert lap values ('fj-2013004','2013-10-11','b-003','hdd 500 gb','700000','800000','1'); insert lap values ('fj-2013005','2012-10-01','b-001','laptop apple','500000','700000','3'); insert lap values ('fj-2013006','2013-10-04','b-004','monitor 14"','100000','800000','2'); insert lap values ('fj-2013007','2013-02-01','b-001','laptop apple','700000','850000','4'); insert lap values ('fj-2013008','2013-10-21','b-005','hdd 500 gb','800000','900000','3'); insert lap values ('fj-2013009','2013-10-27','b-001','laptop apple','500000','700000','1');

i think this:

select no_faktur,tgl_jual,kd_barang,nm_barang,harga_jual,jum_jual,sum(harga_jual*jum_jual) total_jual lap month(tgl_jual)='10' , year(tgl_jual)='2013' , jum_jual=(select max(jum_jual) lap group kd_barang) order total_jual desc;

but doesn't work because *jum_jual more 1 rows.

please help, in advance

select no_faktur,tgl_jual,kd_barang,nm_barang,harga_jual,sum(jum_jual) jum_jual,sum(harga_jual*jum_jual) total_jual lap month(tgl_jual)='10' , year(tgl_jual)='2013' group kd_barang order total_jual desc;


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -