1.利用子查询查询最大时间
2.在外层比较时间相等
注意点:max只对当列有效
##
select ta.int_interpreting_data_id,ta.str_value,ta.dt_report_date,ta.dataId,ta.db_name,ta.int_interpreting_data_id,ta.str_property_id
from t_interpreting_data ta,(
select max(dt_report_date) drt
from t_interpreting_data
where str_property_id='Windows Server 2003_244'
group by db_name,str_norm_number
order by dt_report_date desc
) tid
where ta.str_property_id='Windows Server 2003_244' and ta.dt_report_date = tid.drt
group by ta.db_name,ta.str_norm_number
order by ta.str_norm_number desc
CREATE TABLE IF NOT EXISTS `test` (
`id` int(10) unsigned NOT NULL auto_increment,`install` int(10) unsigned NOT NULL,
`day` int(10) unsigned NOT NULL,
`aid` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
INSERT INTO `test` (`id`, `install`, `day`, `aid`) VALUES
(1, 1232, 20080808, 1),
(2, 2321, 20080809, 2),
(3, 1236, 20080810, 3),
(5, 4212, 20080809, 1),
(6, 2312, 20080810, 1),
(7, 1432, 20080811, 1),
(8, 2421, 20080808, 2),
(9, 4245, 20080811, 2),
(10, 5654, 20080810, 2),
(11, 412, 20080808, 3);
SELECT A.* FROM test A,
(SELECT aid, MAX(day) max_day FROM test GROUP BY aid) B
WHERE A.aid = B.aid AND A.day = B.max_day
ORDER BY a.install DESC
网络上搜的到的:http://blog.csdn.net/acmain_chm/article/details/4126306