Subject RE: [firebird-support] Re: Help Group by
Author Graeme Edwards
Something really horrible like this might work but it would be atrociously
slow and a stored procedure would have to be

vastly superior.



The first subselect is designed to return the min value of cost, and the
second one the first order_ID which matches this minimum value.



The distinct is necessary otherwise one record for each order rather than
for each cod_art value will be returned.



Select Distinct Orders1.Cod_Art,

(Select Min(Orders2.Cost) from Orders Orders2 where
Orders1.Cod_Art=Orders2.Cod_Art),

(Select first 1 Orders3.Order_ID from Orders Orders3 where
Order3.Cod_Art=Orders1.Cod_Art and Orders3.Cost=(Select min(Orders4.Cost)
from Orders Orders4 where Orders4.Cod_Art=Orders3.Cod_art) order by
Orders3.Order_ID ASC )

From Orders Orders1





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



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



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





SPONSORED LINKS


Technical
<http://groups.yahoo.com/gads?t=ms&k=Technical+support&w1=Technical+support&
w2=Computer+technical+support&w3=Compaq+computer+technical+support&w4=Compaq
+technical+support&w5=Hewlett+packard+technical+support&w6=Microsoft+technic
al+support&c=6&s=196&.sig=-XIO8GxY6hqd3NaD5WSEyw> support

Computer
<http://groups.yahoo.com/gads?t=ms&k=Computer+technical+support&w1=Technical
+support&w2=Computer+technical+support&w3=Compaq+computer+technical+support&
w4=Compaq+technical+support&w5=Hewlett+packard+technical+support&w6=Microsof
t+technical+support&c=6&s=196&.sig=B29J78SYXnNTjjMFBMznqA> technical
support

Compaq
<http://groups.yahoo.com/gads?t=ms&k=Compaq+computer+technical+support&w1=Te
chnical+support&w2=Computer+technical+support&w3=Compaq+computer+technical+s
upport&w4=Compaq+technical+support&w5=Hewlett+packard+technical+support&w6=M
icrosoft+technical+support&c=6&s=196&.sig=7_je1A94xs82CFXUjEqA6g> computer
technical support


Compaq
<http://groups.yahoo.com/gads?t=ms&k=Compaq+technical+support&w1=Technical+s
upport&w2=Computer+technical+support&w3=Compaq+computer+technical+support&w4
=Compaq+technical+support&w5=Hewlett+packard+technical+support&w6=Microsoft+
technical+support&c=6&s=196&.sig=2zMAuRCo5cJrVBr1Bxa3_w> technical support

Hewlett
<http://groups.yahoo.com/gads?t=ms&k=Hewlett+packard+technical+support&w1=Te
chnical+support&w2=Computer+technical+support&w3=Compaq+computer+technical+s
upport&w4=Compaq+technical+support&w5=Hewlett+packard+technical+support&w6=M
icrosoft+technical+support&c=6&s=196&.sig=_ytYU7aXb57AVaeUfmvLcA> packard
technical support

Microsoft
<http://groups.yahoo.com/gads?t=ms&k=Microsoft+technical+support&w1=Technica
l+support&w2=Computer+technical+support&w3=Compaq+computer+technical+support
&w4=Compaq+technical+support&w5=Hewlett+packard+technical+support&w6=Microso
ft+technical+support&c=6&s=196&.sig=4hRo6NXYavRAbTkaYec5Lw> technical
support



_____

YAHOO! GROUPS LINKS



* Visit your group "firebird-support
<http://groups.yahoo.com/group/firebird-support> " on the web.

* To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
<mailto:firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe>

* Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service.



_____



[Non-text portions of this message have been removed]