show columns from quote;
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
id | int(8) unsigned | NO | PRI | NULL | auto_increment |
code | text | YES | NULL | ||
date | date | YES | NULL | ||
open | double | YES | NULL | ||
high | double | YES | NULL | ||
low | double | YES | NULL | ||
close | double | YES | NULL | ||
volume | bigint(20) | YES | NULL |
select code,max(date) as date from quote group by code;
可以找出每个 code 组里面对应的最大date.
我现在想找出每个组中,最大的date,对应的其他条字段记录,我写成下面的方式
create table b SELECT code,max(date) as date from quote group by code ;
select * from quote as a , b where a.code = b.code and a.date = b.date;
效率很低,请问,如何改进?