I have the result of a subquery:
SELECT
maker, p.type, COUNT(DISTINCT pc.model) pcs
FROM
Product p
INNER JOIN
Pc pc ON p.model = pc.model
GROUP BY
maker, p.type
UNION
SELECT
maker, p.type, COUNT(DISTINCT l.model) pcs
FROM
Product p
INNER JOIN
Laptop l ON p.model = l.model
GROUP BY
maker, p.type
UNION
SELECT
maker, p.type, COUNT(DISTINCT pr.model) pcs
FROM
Product p
INNER JOIN
Printer pr ON p.model = pr.model
GROUP BY
maker, p.type
| maker | type | model |
|---|---|---|
| A | Laptop | 2 |
| A | PC | 2 |
| A | Printer | 3 |
| B | Laptop | 1 |
| B | PC | 1 |
| C | Laptop | 1 |
| D | Printer | 2 |
| E | PC | 1 |
| E | Printer | 1 |
But I need to find the percentage of the number of models of a given type and a given maker to the total number of models from that maker. In other words: divide these values by the total quantity by maker, i.e. SUM(COUNT(pcs))
I should get a table like this:
| maker | type | model |
|---|---|---|
| A | Laptop | 28.57 |
| A | PC | 28.57 |
| A | Printer | 42.86 |
| B | Laptop | 50.00 |
| B | PC | 50.00 |
| C | Laptop | 100.00 |
| D | Printer | 100.00 |
| E | PC | 50.00 |
| E | Printer | 50.00 |