SELECT item, SUM(left_items) AS left_items, MAX(price) AS price
FROM dbo.exchange
WHERE time_end>1 AND left_items>0
GROUP BY item, price;
Select a.item, a.price,SUM(b.left_items) as left_items from
(Select item, MAX(price) as price from dbo.exchange group by item) a
left join
dbo.exchange b
on a.item=b.item and a.price=b.price
group by a.item, a.price