I have record like this pic, PLEASE CLICK TO SHOW PIC
how to get like this pic, PLEASE CLICK TO SHOW PIC
创建表查询:
创建表格记录(no_faktur varchar(30)主键,tgl_jual日期,
kd_barang varchar(20),nm_barang varchar(100),harga_beli int(20),
harga_jual int(20),jum_jual int(10));
插入表查询:
插入单圈值('FJ-2013001','2013-10-01','B-001','笔记本电脑
苹果”,“ 500000”,“ 700000”,“ 2”);插入单圈值
('FJ-2013002','2012-10-01','B-002','笔记本电脑
苹果(Apple),'300000','500000','4');插入单圈值
('FJ-2013003','2013-10-03','B-001','笔记本电脑
苹果('500000','700000','1');插入单圈值
('FJ-2013004','2013-10-11','B-003','HDD 500
GB','700000','800000','1');插入单圈值
('FJ-2013005','2012-10-01','B-001','笔记本电脑
苹果('500000','700000','3');插入单圈值
('FJ-2013006','2013-10-04','B-004','MONITOR
14“','100000','800000','2');插入到单圈值中
('FJ-2013007','2013-02-01','B-001','笔记本电脑
苹果”,“ 700000”,“ 850000”,“ 4”);插入单圈值
('FJ-2013008','2013-10-21','B-005','HDD 500
GB','800000','900000','3');插入单圈值
('FJ-2013009','2013-10-27','B-001','笔记本电脑
苹果('500000','700000','1');
我认为是这样的:
选择
no_faktur,tgl_jual,kd_barang,nm_barang,harga_jual,jum_jual,sum(harga_jual * jum_jual)作为一个月的总_jual,其中month(tgl_jual)='10'并且
year(tgl_jual)='2013'和jum_jual =(从圈中选择max(jum_jual)
按kd_barang分组)按total_jual desc排序;
但是不起作用,因为* jum_jual多于1行。
请帮助,在此先感谢
最佳答案
选择no_faktur,tgl_jual,kd_barang,nm_barang,harga_jual,sum(jum_jual)作为jum_jual,sum(harga_jual * jum_jual)作为total_jual
从月(tgl_jual)='10'和年(tgl_jual)='2013'的那一圈开始
按kd_barang分组
按total_jual desc排序;
关于mysql - 选择字段GROUP BY max(field)和GROUP BY其他字段MySQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40532038/