A
A
Alexey Lebedev2015-08-31 12:33:23
SQL
Alexey Lebedev, 2015-08-31 12:33:23

How to remove the extra from the request?

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;

a3a15c4a613040ba8b93ff541b4dcfe0.png
It is necessary that there would be no line 2 (3 5 5).
The goal is to offer the best value for money.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2015-08-31
@swanrnd

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

How so unfaithful

A
Alexey Sh, 2015-08-31
@bondpuoq

I think you should use partition by here, like this:
SELECT item,
sum(left_items) over (partition by item order by price) as left_items,
first_value(price) over (partition by item order by price) as price
WHERE time_end>1 AND left_items>0
If I understand correctly, it should be like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question