Subject Re: [firebird-support] Re: Help Group by
Author Adomas Urbanavicius
Obviously you havent tried this in sql editor.
It works perfectly.

Adomas

Graeme Edwards wrote:

>Syntax not checked, but idea :
> select
> orders1.cod_art,
> min(MinCost),
> ( select first 1 orders2.order_id from orders orders2
> where
> orders2.cod_art = orders1.cod_art order by mincost asc
> ) ///subselect returns first 1 order_id with cod_art =
>order1.cod_art and min(mincost)
> from
> orders orders1
> group by orders1.cod_art;
>
>
>Adomas
>
>
>
>The problem with this is that the subselect effectively creates an extra
>field in the query, and this field
>
>is not an aggregate function or contained in the group by list, so you will
>get the standard sql error to
>
>this effect.
>
>
>
>Using a stored procedure as already suggested seems to be the only way round
>this.
>
>
>
>Graeme
>
>
>
>
>Alberto Pesce wrote:
>
>
>
>>Hi all collaborators,
>> Based on the example I need from table orders
>>
>>order_ID Cod_art Cost
>>-------- ------- ----
>>1 1 10
>>2 2 20
>>3 1 15
>>4 3 20
>>5 3 22
>>
>>this from the query
>>
>>Cod_art MinCost order_ID
>>------- -------- ---------
>>1 10 1
>>2 20 2
>>3 20 4
>>
>>Thank very much
>> Bye
>>
>>
>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>
>>Visit http://firebird.sourceforge.net and click the Resources item
>>on the main (top) menu. Try Knowledgebase and FAQ links !
>>
>>Also search the knowledgebases at http://www.ibphoenix.com
>>
>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>


--

Pagarbiai / Best Regards,
Adomas Urbanavicius
+37068543336