Let's say I have the following table:
create table orders (id int, order_id int, vendor varchar, price int);
INSERT INTO orders values
(1, 1, 'nike', 10),
(2, 2, 'nike', 10),
(3, 3, 'adidas', 15),
(4, 3, 'adidas', 15);
I want to get the sum of the price per distinct order_id and grouped by vendor. So the answer here would be:
| vendor | sum |
| nike | 20 |
| adidas | 15 |
The reason why adidas is 15 is because we only grab one of the prices since the other adidas record has the same order_id. Is it also possible to do this without a nested query?