groupby用法

每个类别提取最新一条记录

按编号来:

select max(topicid) as topicid from tb_bbs_topic

where

boardid in(6,10,34,12,33,13,18,21,51,49) group by boardid
如果是按日期来的话:

select * from tb_bbs_topic a
inner join
(
select boardid, max(dateandtime) as dateandtime
from tb_bbs_topic b
where boardid in(6,10,34,12,33,13,18,21,51,49)
group by boardid
)

b on a.boardid=b.boardid and a.dateandtime=b.dateandtime

posted on 2009-11-12 12:41  fery  阅读(331)  评论(1编辑  收藏  举报