请问这个功能是怎么实现的啊?

shuqiyiling 2011-07-02 08:29:11
各位大侠,我想是实现一个多人博客网站一个功能,我建了一张表,该表中提供了访问ID(主键),博主姓名,访问者的姓名(可以为匿名,可以重复访问),访问时间等字段,我想实现类似腾讯空间中近期访问列表,列表中不能出现重复的访问者姓名,并能按照时间按排序,再者就是只显示前10条记录,高手帮忙……
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuqiyiling 2011-07-02
  • 打赏
  • 举报
回复
嗯嗯,谢谢各位的帮忙……
AcHerat 2011-07-02
  • 打赏
  • 举报
回复
楼主可以试试1楼和3楼的,把那个非空的条件加进去。



select top 10 *
from tb t
where not exists (select 1 from tb where name = t.name and name <> '' and date > t.date)
and name <> ''
order by date desc
shuqiyiling 2011-07-02
  • 打赏
  • 举报
回复
where exists (select * from visiter where vist_name!='') //查找到vist_name非空的数据集
and exists (select top 600* from visiter order by vist_time desc) //将数据按vist_time排序,
两个条件同时构成
select top 10 vist_name
from visiter的查询数据源,
这种思路是不是有误?


AcHerat 2011-07-02
  • 打赏
  • 举报
回复
上边少了个group by。。。
AcHerat 2011-07-02
  • 打赏
  • 举报
回复

select top 6 vist_name
from visiter
where vist_name!=''
order by max(vist_time) desc -- and vist_name in (select top 600 vist_name from visiter order by vist_time desc)


楼主的逻辑是怎样的 ?
shuqiyiling 2011-07-02
  • 打赏
  • 举报
回复
向高手致敬,十分感谢,我用你的方法实现了,不过稍微做了一下修改,
select top 10 vist_name
from visiter
where vist_name!=''
group by vist_name
order by max(vist_time) desc

请问这段代码那里出问题了呢,谢谢……
select distinct top 6 vist_name
from visiter
where exists (select * from visiter where vist_name!='')
and exists (select top 600* from visiter order by vist_time desc)
AcHerat 2011-07-02
  • 打赏
  • 举报
回复

select top 10 *
from tb t
where not exists (select 1 from tb where name = t.name and date > t.date)
order by date desc
yubofighting 2011-07-02
  • 打赏
  • 举报
回复

select top 10 * from tbname a

where not exists (select 1 from tbname b where a.id<>b.id and a.name=b.name)

order by 你想要排序的字段
AcHerat 2011-07-02
  • 打赏
  • 举报
回复

select top 10 name
from tb
group by name
order by max(date) desc

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧