> > 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 I run only the last subquery (select symbol, max(trade_time/trade_id) from trade group by symbol) something strange happens. I have separate indexes on symbol,trade_id and symbol,trade_time. Also, I have another index that serves different purposes, but it contains symbol, trade_date and trade_time (and a few other). Now, the strange thing is that this last index (the large one) is used whether I select max(trade_time) or max(trade_id). The first statement can be explained since trade_time is in this index, but the second one is strange since trade_id is not included in the index. This causes the query to run 3x slower. The optimiser has to be doing something wrong. Actually, I've now set trade_id and symbol to be the primary key and it still uses the large index. Cheers, Dag _______________________________________________ sapdb.general mailing list [EMAIL PROTECTED] http://listserv.sap.com/mailman/listinfo/sapdb.general
