即時通訊有問題獲得一個查詢輸出我怎麼想,Mysql的DISTINCT和COUNT查詢
SELECT
`orders`.`item_id`,
`products`.`item_code`,
`products`.`item_name`,
`orders`.`quantity`
FROM
`orders`
JOIN `products` ON `orders`.`item_id` = `products`.`id`
JOIN `suppliers` ON `products`.`supplier_ref` = `suppliers`.`supplier_ref`
WHERE
`suppliers`.`id` = 159
AND `orders`.`order_status` = 'NOTED'
這是返回結果:
item_id item_code item_name quantity
1271 RA001G Green Mop Bucket 12L 2
1270 RA001 Blue Mop Bucket 12L 1
1270 RA001 Blue Mop Bucket 12L 1
,但我想它帶回不同的ITEM_ID與數量加在一起如何,當我已經嘗試添加不同並計數我最終只有一行返回。
使用組,那麼你應該添加一個'組by'條款。 –
你想看到「1270 RA001藍色拖把桶12L 2」的輸出? –