Actually my requirement is for the price of an item with the nearest time i specified. And I have multiple conditions satisfy.
I have an index of price data of different instruments(scripts) with the following index fields. id, name, price, type, exchange time. ex: 1, Microsoft, 120$, 1, NYSE, 200909132626 And I want to qurey for price by using the following parameters: id: Instrument id time Date and time that a price is sought for type Type of price sought: 1= Opening, 2= closing etc exchange The exchange that a price is sought for.
The following conditions need to be handled: 1. If a price exists at the exact date – time that is requested then return that price. 2. if not return the instrument whose timestamp is closest to the requested time. 4. If no price exists for the type, return the opening price 5. else previous day closing 6. else return null.
I tried something like getting data with: time:[day begining time stamp TO requesed time stamp]. sort(). getMaxresult(1).list() ;
I wanted to remove the sort part. And also wanted to put all conditions in a single query. How I can approach this with best performence.
|