将聚合子查询转换成JOIN
CUSTOMER DAY_TIME TOTAL
jeff 2007-1-3 22
jeff 2008-1-3 32
jeff 2009-2-1 5
tirry 2008-8-2 33
需要结果为每个customer total字段最大的记录
select c1.* From C c1
where c1.day_time=(select max(day_time) from C c2 where c1.customer=c2.customer)
这个是使用子查询方法的SQL
select c1.* from C c1,C c2 where c1.customer=c2=customer group by c1.customer,c1.day_time,c1.total
having c1.day_time=max(c2.day_time)
阅读(1539) | 评论(0) | 转发(0) |