简体   繁体   中英

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 ?

Add a GROUP BY clause in your query

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM