By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
/* Table Sales */
CREATE TABLE sales (
id int auto_increment primary key,
product VARCHAR(255),
KPI VARCHAR(255),
sales_volume INT
);
INSERT INTO sales
(product, KPI, sales_volume)
VALUES
("Product A", "sold", "500"),
("Product A", "sold", "300"),
("Product B", "sold", "200"),
("Product C", "sold", "300"),
("Product D", "sold", "900");
/* Table Logistics */
CREATE TABLE logistics (
id int auto_increment primary key,
product VARCHAR(255),
KPI VARCHAR(255),
quantity INT
);
INSERT INTO logistics
(product, KPI, quantity)
VALUES
("Product A", "outbound", "800"),
("Product B", "outbound", "100"),
("Product B", "outbound", "400"),
("Product C", "outbound", "250"),
("Product D", "outbound", "900");
SELECT
product,
KPI,
SUM(sales_volume)
FROM sales
GROUP BY 1
UNION ALL
SELECT
product,
KPI,
SUM(quantity)
FROM logistics
GROUP BY 1
product | KPI | SUM(sales_volume) |
---|---|---|
Product A | sold | 800 |
Product B | sold | 200 |
Product C | sold | 300 |
Product D | sold | 900 |
Product A | outbound | 800 |
Product B | outbound | 500 |
Product C | outbound | 250 |
Product D | outbound | 900 |