sql面试题求解
发布网友
发布时间:2022-04-09 09:40
我来回答
共4个回答
热心网友
时间:2022-04-09 11:10
方法1:
Select * from p a where not exists(select 1 from p where phone=a.phone and calltime>a.calltime)
方法2:
select a.* from p a join (select max(calltime)calltime,phone from p group by phone) b on a.phone=b.phone and a.ID=b.ID order by calltime
方法3:
select * from p a where ID=(select max(ID) from p where phone=a.phone) order by calltime
方法4:
select a.* from p a join p b on a.phone=b.phone and a.calltime<=b.calltime group by a.calltime,a.phone,a.Memo having count(1)=1
方法5:
select * from p a group by calltime,phone,Memo having ID=(select max(calltime)from p where phone=a.phone)
方法6:
select * from p a where (select count(1) from p where phone=a.phone and calltime>a.calltime)=0
方法7:
select * from p a where calltime=(select top 1 calltime from p where phone=a.phone order by calltime desc)
方法8:
select * from p a where calltime!<all(select calltime from p where phone=a.phone)
方法9(注:ID为唯一时可用):
select * from p a where calltime in(select max(calltime) from p group by phone)
热心网友
时间:2022-04-09 12:28
1 .select top 1 * from p group by phone order by id desc
--ID上自动增长的,先按手机号码分组,降序取第一个,就是最近的通话记录!
2.select * from p where id in(select max(id) from p group by phone)
--查出分组号码中最大的ID,再查询表中所对应的ID,就是最近通话记录
呵呵,上面的比较简单易懂
热心网友
时间:2022-04-09 14:02
select * from p gruop by phone
select * from p where phone in (select distic phone from p)
热心网友
时间:2022-04-09 15:54
select id,phone,calltime from p ORDER BY
calltime DESC