Subject | Re: Help Group by |
---|---|
Author | Adam |
Post date | 2006-03-15T23:17:38Z |
--- In firebird-support@yahoogroups.com, "Alberto Pesce"
<palberto@...> wrote:
Orders
======
order_ID Cod_art Cost
-------- ------- ----
1 1 10
2 2 20
3 1 15
4 3 20
5 3 22
Your first query would return
Cod_art MinCost
------- --------
1 10
2 20
3 20
Now Cod_art 1 could be order_id 1 OR 3??
Cod_art 2 will be 2
How could you possibly tell which should go first? You cant.
Alexandre's second query is probably the one you want.
Adam
<palberto@...> wrote:
>Imagine you had the following table
> I need to make this query:
> the lower cost of product ordered for each oreder.
>
> this work well
>
> SELECT cod_art, MIN(cost)
> FROM orders
> GROUP BY cod_art
>
> but this return each row in orders
>
> SELECT order_ID, cod_art, MIN(cost)
> FROM orders
> GROUP BY order_ID, cod_art
>
> How can I add order_ID in the first query?
Orders
======
order_ID Cod_art Cost
-------- ------- ----
1 1 10
2 2 20
3 1 15
4 3 20
5 3 22
Your first query would return
Cod_art MinCost
------- --------
1 10
2 20
3 20
Now Cod_art 1 could be order_id 1 OR 3??
Cod_art 2 will be 2
How could you possibly tell which should go first? You cant.
Alexandre's second query is probably the one you want.
Adam