SQL面试题,急求救!
某个表有两个字段(phone和sendtime)
phone sendtime
13908000800 2006-3-8 16:20:25
13918001800 2006-3-8 17:15:20
13908000800 2006-3-8 16:25:25
13908000800 2006-3-9 07:15:20
......
请写出一个sql语句,实现的功能为:取出每个号码(phone)的最新发送时间(sendtime)的记录?
问题点数:20、回复次数:8Top
1 楼lsqkeke(可可)回复于 2006-03-09 09:55:13 得分 5
select * from tb a
where not exists(select * from tb where phone=a.phone and sendtime>a.sendtime)Top
2 楼genphone_ru(哎,什么都要学,真累)回复于 2006-03-09 09:55:25 得分 5
select phone,max(sendtime) as sendtime from tablename group by phoneTop
3 楼lsqkeke(可可)回复于 2006-03-09 09:55:52 得分 5
select phone,max(sendtime) from tb group by phoneTop
4 楼libin_ftsafe(子陌红尘:TS for Banking Card)回复于 2006-03-09 09:56:07 得分 5
select phone,max(sendtime) as sendtime from 表 group by phoneTop
5 楼cd913td198()回复于 2006-03-09 10:10:03 得分 0
如果这个表中有还有其它字段(如name)应该怎样处理呢?Top
6 楼cd913td198()回复于 2006-03-09 10:10:28 得分 0
顶Top
7 楼yaoyaogghaha(yaogg)回复于 2006-05-19 08:54:14 得分 0
select t.b,t.c into #t
from
(
select '13908000800' b ,'2006-3-8 16:20:25' c
union
select '13918001800' b ,'2006-3-8 17:15:20' c
union
select '13908000800' b ,'2006-3-8 16:25:25' c
union
select '13908000800' b ,'2006-3-9 07:15:20' c
) t
select b,max(c) from #t group by b
drop table #tTop
8 楼liusujian02(刘阿建)回复于 2006-07-03 00:03:22 得分 0
markTop




