tags:

views:

56

answers:

2

Hello

I have this mysql table:

id       - auto_increment
id_stock - int
price    - double
date     - date

sample data is:

1   1   10.5   2010-08-10
2   1   16.5   2010-08-11
3   2   12.5   2010-08-12

now, i have to group by id_stock and search for the MAX(date) of the stock, then i have to compare the MAX(date) to a date i have to pass.

How to do it?

Thank you really much

+4  A: 
 SELECT ...
 FROM Table
 GROUP BY Id_Stock
 HAVING Max(Date) = YourPassedDate
Michael Pakhantsov
+1  A: 

You should be able to get this using 'group' and 'having' together:

select id, MAX(date) as max_date from test group by id_stock having max_date > '2010-08-11'

jkilbride