thử
SELECT sum(processed_weight) AS total_qty
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38'
EDIT 2 - SAU bình luận từ OP thay đổi cấu trúc kết quả:
Đối với một thử cột bổ sung:
SELECT
X.supplier,
X.total_qty,
(SELECT sum(processed_weight)
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38') AS totalq
FROM
(
SELECT
a.id AS supplier,
sum(processed_weight) AS total_qty,
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38'
GROUP BY b.supplier) AS X
Đối với hàng additonal:
SELECT
a.id AS supplier,
sum(processed_weight) AS total_qty
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38'
GROUP BY b.supplier
UNION ALL
SELECT null, X.total_qty
FROM
(
SELECT sum(processed_weight) AS total_qty
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38') AS X
Bạn có cần nó như là một tiện ích hàng itional trong cùng một kết quả? Hay bạn muốn chạy một SELECT thứ hai? –
yup @a_horse_with_no_name – Ghostman
* yup * cái gì? Tôi hỏi hai câu hỏi. –