How to design the sql for this problem?# Database - 数据库
c*n
1 楼
a table fctTbl contains following fields: A1, A2, date, value; the primary
key is. The example "date" value is 20090520 (May 20 2009),
20090601 ....
fctTble has 1 millon rows in it.
The question is, how to get the result set with coloumn A1,A2,value, where
the maximum date rows are returned.
Following code is my solution, and it takes forever to run. I want to ask
whether you have better ideas.
select t1.A1,t1.A2,t2.value from
(select A1,A2,max(date) as date from fctTbl group by A1
key is
20090601 ....
fctTble has 1 millon rows in it.
The question is, how to get the result set with coloumn A1,A2,value, where
the maximum date rows are returned.
Following code is my solution, and it takes forever to run. I want to ask
whether you have better ideas.
select t1.A1,t1.A2,t2.value from
(select A1,A2,max(date) as date from fctTbl group by A1