[英]Count of rows with same field value
I have query我有查询
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 = 'Отправлять'
Which is returning this result .这是返回这个结果。
How could I get count of rows with the same salesorderid
and count of rows with same salesorderid
and shipping_order_row_good_id
?如何获得具有相同
salesorderid
的行数和具有相同salesorderid
和shipping_order_row_good_id
的行数?
Add a GROUP BY
clause in your query在查询中添加
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
If you want to sum the quantity of each salesorder
and integration_betapost.goods_to_products.shipping_order_row_good_id
, you can change COUNT
for SUM
.如果您想对每个
salesorder
和integration_betapost.goods_to_products.shipping_order_row_good_id
的数量求和,您可以将COUNT
更改为SUM
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.