当我使用 group by 子句时如何避免分组列
How to avoid a column for grouping when I am using group by clause
我想从分组中删除一列,因为当我使用 group by 子句时它给出了错误的结果。
这里是查询
select co.documentNo as documentno
, mproduct.upc as upc
, mproduct.name as itemcode
, mproduct.em_cl_modelname as modelname
, sum(prod.quantity) as quantity
from OBWPACK_Box box
,OBWPACK_Movlinebox prod
,packingh header
,partner partner
,product mproduct
,order co
,orderline col
,m_inout minout
where box.packingh_id=header.packingh_id
and prod.obwpack_box_id=box.obwpack_box_id
and partner.partner_id=header.partner_id
and mproduct.product_id=prod.product_id
and col.order_id=co.order_id
and col.orderline_id=prod.orderline_id
and co.order_id=minout.order_id
and minout.docstatus='CO'
and box.trackingNo='EDGER'
and partner.name='102'
group by prod.quantity,mproduct.name,mproduct.em_cl_modelname,mproduct.upc, co.documentNo
结果是
document upc itemcode sum
I1001717 3583782495440 1132004 1
1001717 3583788674153 1719722 2
1001717 3583788674153 1719722 5
但我想得到如下
document upc itemcode sum
I1001717 3583782495440 1132004 1
1001717 3583788674153 1719722 7
从 Group by
中删除 prod.quantity
SELECT co.documentNo AS documentno,
mproduct.upc AS upc,
mproduct.NAME AS itemcode,
mproduct.em_cl_modelname AS modelname,
Sum(prod.quantity) AS quantity
FROM OBWPACK_Box box,
OBWPACK_Movlinebox prod,
packingh header,
partner partner,
product mproduct,
order co,
orderline col,
m_inout minout
WHERE box.packingh_id = header.packingh_id
AND prod.obwpack_box_id = box.obwpack_box_id
AND partner.partner_id = header.partner_id
AND mproduct.product_id = prod.product_id
AND col.order_id = co.order_id
AND col.orderline_id = prod.orderline_id
AND co.order_id = minout.order_id
AND minout.docstatus = 'CO'
AND box.trackingNo = 'EDGER'
AND partner.NAME = '102'
GROUP BY mproduct.NAME,
mproduct.em_cl_modelname,
mproduct.upc,
co.documentNo
我想从分组中删除一列,因为当我使用 group by 子句时它给出了错误的结果。
这里是查询
select co.documentNo as documentno
, mproduct.upc as upc
, mproduct.name as itemcode
, mproduct.em_cl_modelname as modelname
, sum(prod.quantity) as quantity
from OBWPACK_Box box
,OBWPACK_Movlinebox prod
,packingh header
,partner partner
,product mproduct
,order co
,orderline col
,m_inout minout
where box.packingh_id=header.packingh_id
and prod.obwpack_box_id=box.obwpack_box_id
and partner.partner_id=header.partner_id
and mproduct.product_id=prod.product_id
and col.order_id=co.order_id
and col.orderline_id=prod.orderline_id
and co.order_id=minout.order_id
and minout.docstatus='CO'
and box.trackingNo='EDGER'
and partner.name='102'
group by prod.quantity,mproduct.name,mproduct.em_cl_modelname,mproduct.upc, co.documentNo
结果是
document upc itemcode sum
I1001717 3583782495440 1132004 1
1001717 3583788674153 1719722 2
1001717 3583788674153 1719722 5
但我想得到如下
document upc itemcode sum
I1001717 3583782495440 1132004 1
1001717 3583788674153 1719722 7
从 Group by
prod.quantity
SELECT co.documentNo AS documentno,
mproduct.upc AS upc,
mproduct.NAME AS itemcode,
mproduct.em_cl_modelname AS modelname,
Sum(prod.quantity) AS quantity
FROM OBWPACK_Box box,
OBWPACK_Movlinebox prod,
packingh header,
partner partner,
product mproduct,
order co,
orderline col,
m_inout minout
WHERE box.packingh_id = header.packingh_id
AND prod.obwpack_box_id = box.obwpack_box_id
AND partner.partner_id = header.partner_id
AND mproduct.product_id = prod.product_id
AND col.order_id = co.order_id
AND col.orderline_id = prod.orderline_id
AND co.order_id = minout.order_id
AND minout.docstatus = 'CO'
AND box.trackingNo = 'EDGER'
AND partner.NAME = '102'
GROUP BY mproduct.NAME,
mproduct.em_cl_modelname,
mproduct.upc,
co.documentNo