Wednesday, March 28, 2012

ORDER BY Question

Item Quantity
I1 10
I2 7
I1 5
Assume that is the Data.
I want it ordered by Quantity FIRST and then show the same Item again
if it exists.
How can I display it in this way
Item Quantity
I1 10
I1 5
I2 7
P.S Please do not say "ORDER BY Item, Quanity DESC"I'll guess you want to order by max(Quantity) for the same item.
select
T.Item,
T.Quantity
from T
join (
select Item, max(Quantity) as maxQuantity
from T
group by Item
) as Tmax
on Tmax.Item = T.Item
order by maxQuantity desc
[Not tested, but I hope you get the idea]
Steve Kass
Drew University
rythm wrote:

> Item Quantity
>I1 10
>I2 7
>I1 5
>Assume that is the Data.
>I want it ordered by Quantity FIRST and then show the same Item again
>if it exists.
>How can I display it in this way
>Item Quantity
>I1 10
>I1 5
>I2 7
>P.S Please do not say "ORDER BY Item, Quanity DESC"
>|||Thanks that did work.
After looking at it, it seems so simple.
I couldn't even think of performing it in that ordersql

No comments:

Post a Comment