我有查询
SELECT
salesorderid,
integration_betapost.goods_to_products.shipping_order_row_good_id,
vtiger_inventoryproductrel.quantity
FROM
vtiger_salesorder
INNER JOIN vtiger_inventoryproductrel ON vtiger_salesorder.salesorderid = vtiger_inventoryproductrel.id
INNER JOIN vtiger_products ON vtiger_inventoryproductrel.productid = vtiger_products.productid
INNER JOIN integration_betapost.goods_to_products ON vtiger_products.productid = integration_betapost.goods_to_products.productid
WHERE
sostatus = 'Отправлять'
得到这个result
如何计算具有相同salesorderid
的行数和具有相同salesorderid
和shipping_order_row_good_id
的行数?
答案 0 :(得分:3)
在查询中添加GROUP BY
子句
SELECT
salesorderid,
integration_betapost.goods_to_products.shipping_order_row_good_id,
COUNT(Quantity)
FROM
vtiger_salesorder
INNER JOIN vtiger_inventoryproductrel ON vtiger_salesorder.salesorderid = vtiger_inventoryproductrel.id
INNER JOIN vtiger_products ON vtiger_inventoryproductrel.productid = vtiger_products.productid
INNER JOIN integration_betapost.goods_to_products ON vtiger_products.productid = integration_betapost.goods_to_products.productid
WHERE
sostatus = 'Отправлять'
GROUP BY
salesorderid
,integration_betapost.goods_to_products.shipping_order_row_good_id
如果您想对每个salesorder
和integration_betapost.goods_to_products.shipping_order_row_good_id
的数量求和,可以更改COUNT
的{{1}}。