Dag �yvind Liodden wrote:

> > > EXPLAIN says (I apologize if this table is hard to read):
> > >
> > > OWNER      TABLENAME  COLUMN_OR_INDEX     STRATEGY
> > >           PAGECOUNT
> > >    T1                             TABLE SCAN
> > >           140
> > > INTERNAL TEMPORARY RESULT         EQUAL CONDITION FOR KEY
> > > COLUMN            500
> > >            TRADE_ID                         (USED KEY COLUMN)
> > > T2                                        NO STRATEGY NOW (ONLY
> > > AT EXECUTION TIME)140
> > > TROODON                                   RESULT IS
> > > COPIED   , COSTVALUE IS   1352
> > >
> > > The query runs in about 1,352 seconds (is this what the last
> > > pagecount means?)
> >
> > No, costvalue does NOT mean seconds, it means: expected pages to
> > be read/written.
> 
> OK, just a coincidence, then. :) Why does it say "COSTVALUE IS" but no
> real value?


   COSTVALUE means the number of pages to read/write.
   Noone before really doing it has any idea how many of those pages have to
   be read/written physically, how many are in the data cache.
   Because of the known difference of time consumption between those two
   kinds of reading/writing, no 'real value' in seconds or whatever can be
given.
  
> 
> > > I guess the ideal thing would be if the following had been
> > > possible (but
> > > it's not :):
> > >
> > > select symbol, last(change), last(price), last(trade_time),
> > > last(volume)
> > > from
> > > trade
> > > group by symbol
> >
> >
> > Do you mean select symbol, MAX(change), MAX(price), 
> MAX(trade_time) ... ?
> 
> No, I want the last change, price and trade_time. With MAX I 
> will will get
> the last trade_time (since they are always increasing) but 
> not the last
> change and price.

   If you want to receive the last trade for each symbol and all
   the values stored for this single trade and you know that trade_time
   is (of course) increasing then you should use this:
   SELECT symbol, change, price, trade_time, volume
   FROM trade
   WHERE (symbol, trade_time) = ANY
           (SELECT symbol, MAX(trade_time)
            FROM trade
           GROUP BY symbol)

If you have to limit the symbols selected then
BOTH selects should use this limitation, of course at least the top one. 

If you want to order them, append for example an ORDER BY change to the
query given above.

Elke
SAP Labs Berlin
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general

Reply via email to