Subject | Re: [firebird-support] Help Group by |
---|---|
Author | Alexandre Benson Smith |
Post date | 2006-03-15T18:31:21Z |
Alberto Pesce wrote:
I don't know if I get it right... but I think it's something like:
SELECT
o1.order_ID, o1.cod_art, o1.cost
FROM
orders o1
where
o1.cost = (Select Min(o2.cost) from orders o2 where o2.order_id o1.order_id)
the above query will return be item with lower cost inside an order.
or this one:
SELECT
o1.order_ID, o1.cod_art, o1.cost
FROM
orders o1
where
o1.cost = (Select
min(o2.cost)
from
orders o2
where
o2.cod_art = o1.cod_art
)
This should return the order_id, cod_art, cost from the order (or orders
in case of a draw) that has the lower cost for each cod_art
This query should be a bit slow... :-(
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
> I need to obtain a order identificator where cod_art it is at lower cost.Alberto,
>
> Thanks
> bye
>
I don't know if I get it right... but I think it's something like:
SELECT
o1.order_ID, o1.cod_art, o1.cost
FROM
orders o1
where
o1.cost = (Select Min(o2.cost) from orders o2 where o2.order_id o1.order_id)
the above query will return be item with lower cost inside an order.
or this one:
SELECT
o1.order_ID, o1.cod_art, o1.cost
FROM
orders o1
where
o1.cost = (Select
min(o2.cost)
from
orders o2
where
o2.cod_art = o1.cod_art
)
This should return the order_id, cod_art, cost from the order (or orders
in case of a draw) that has the lower cost for each cod_art
This query should be a bit slow... :-(
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br