Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-2008, 09:19 PM
larry@portcommodore.com
 
Posts: n/a
Default Looking up a row of data based on amount and date

I'm trying to look up a value on a lookup table based on an amount and
a date

Now the "lookup-tables" change from period to period so the main
"tables" record has a start and end date and id

SELECT table_id FROM tables
$date >= startdate AND $date <= enddate

next I need to select the right row from the "tablelist" table (which
has all the lookup data) based on a column item that is the maximum
value but less than or equal to the amount


SELECT * FROM tablelist
WHERE table_id = $table_id
AND amount = SELECT MAX(amount) WHERE amount <= $testamount

I think I'm close, how would I roll it all into one?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-02-2008, 12:00 PM
Captain Paralytic
 
Posts: n/a
Default Re: Looking up a row of data based on amount and date

On 1 Apr, 21:19, la...@portcommodore.com wrote:
> I'm trying to look up a value on a lookup table based on an amount and
> a date
>
> Now the "lookup-tables" change from period to period so the main
> "tables" record has a start and end date and id
>
> SELECT table_id FROM tables
> $date >= startdate AND $date <= enddate
>
> next I need to select the right row from the "tablelist" table (which
> has all the lookup data) based on a column item that is the maximum
> value but less than or equal to the amount
>
> SELECT * FROM tablelist
> WHERE table_id = $table_id
> AND amount = SELECT MAX(amount) WHERE amount <= $testamount
>
> I think I'm close, how would I roll it all into one?


Could you post some create table statements and some sample data in
the form of extended inserts with the expected output from said sample
data?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:28 AM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.