I have a table with the following columns
  id => int not null auto_increment
  stockid => integer
  tdate => date
  price => float
  primary key (id)
  key (productid)

The table has 8,000,000+ rows holding 8000+ different stockids.

I have to pull various information from the table the first query is to get
the average
price for the last 10 days.

select avg(price) from table1 where tdate>date_sub(today, interval 10 day)

  1. How can I optimize this query?
  2. Are there any advantages to using an index on the tdate column?

Secondly, I need to get all stockids which have today's price greater than
yesterday's.

   Here is how I do this now I am looking for a single statement if
possible.

   select price where tdate=yesterday and stockid=xxx
   select price where tdate=today and stockid=xxx
   compare selected values

  1.  Is this possible with one select?
  2.  Best way to optimize the table for quickest access to the data?


Thanks in advance.

Edward


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to