显示不重复的最新几条记录!!!!!!!!!!!!

redstorm11 2003-12-25 03:25:44
我的access库中有表up2,有字段biaoti,其数据为ab,abb,ab,ab,abbb等,,有字段id(自动编号),现在,我要显示出来的东西是:按id的降序输出biaoti不重复的6条记录,如输出为abbb,ab,abb
在线等
!!!!!!!!!!!!!!!!!!!!!!先谢了
...全文
48 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
redstorm11 2003-12-25
  • 打赏
  • 举报
回复
ok
patchclass 2003-12-25
  • 打赏
  • 举报
回复
select top 6 biaoti from (select distinct biaoti from up2)
sxsgssgs 2003-12-25
  • 打赏
  • 举报
回复
你也可以建立一个视图

create view distincttable
as
select distinct content from table

然后在asp里写:sql="select * from distincttable order by id desc"
sxsgssgs 2003-12-25
  • 打赏
  • 举报
回复
<%rs.movelast%>
<%for i=0 to rs.recordcount%>
<tr>
<td><%=rs("content")%></td>
</tr>
<%rs.moveprevious%>
<%next%>

这个就是倒序代码
redstorm11 2003-12-25
  • 打赏
  • 举报
回复
具体点
czp98069806 2003-12-25
  • 打赏
  • 举报
回复
取值的时候从最后一条取起
redstorm11 2003-12-25
  • 打赏
  • 举报
回复
取得id降序排列的前6条不重复记录,用distinct和order存在冲突问题,所以我不知道怎么写,distinct和top也有问题,如果不能的话,有没有其他办法来解决这个问题呢?》
期待中。。。。。。。。。。。。。。。。。。。
redstorm11 2003-12-25
  • 打赏
  • 举报
回复
sqlstr1="select distinct corporation_id from zpyx order by fb_date desc "

我还要取降序中的前6条,怎么取啊,,请详细点,,,谢了。。。期待中!
redstorm11 2003-12-25
  • 打赏
  • 举报
回复
sqlstr="select biaoti distinct from up2"
可以得到不重复的,但我还要以id降序排列啊


select top 6 distinct biaoti from up2 order by id desc
我开始是用的,但行,在库了说distinct与order不能这样用啊
ying1234 2003-12-25
  • 打赏
  • 举报
回复
select top 6 distinct biaoti from up2 order by id desc
xtyqzp 2003-12-25
  • 打赏
  • 举报
回复
请看一下下面的语句:
sqlstr1="select distinct corporation_id from zpyx order by fb_date desc "
不知为什么编译通不过?
将distinct去掉就可以运行了。
whb147 2003-12-25
  • 打赏
  • 举报
回复
sqlstr="select distinct biaoti from up2"


使用 DISTINCT 消除重复项
DISTINCT 关键字可从 SELECT 语句的结果中除去重复的行。如果没有指定 DISTINCT,那么将返回所有行,包括重复的行。例如,如果在 titleauthor 中选择所有作者 ID 时未使用 DISTINCT,那么将会返回下列行(其中包括一些重复的行):

USE pubs
SELECT au_id
FROM titleauthor

下面是结果集:

au_id
-----------
172-32-1176
213-46-8915
213-46-8915
238-95-7766
267-41-2394
267-41-2394
274-80-9391
409-56-7008
427-17-2319
472-27-2349
486-29-1786
486-29-1786
648-92-1872
672-71-3249
712-45-1867
722-51-5454
724-80-9391
724-80-9391
756-30-7391
807-91-6654
846-92-7186
899-46-2035
899-46-2035
998-72-3567
998-72-3567

(25 row(s) affected)

而使用了 DISTINCT 后,就能够除去重复项,而只查看唯一的作者 ID:

USE pubs
SELECT DISTINCT au_id
FROM titleauthor

下面是结果集:

au_id
-----------
172-32-1176
213-46-8915
238-95-7766
267-41-2394
274-80-9391
409-56-7008
427-17-2319
472-27-2349
486-29-1786
648-92-1872
672-71-3249
712-45-1867
722-51-5454
724-80-9391
756-30-7391
807-91-6654
846-92-7186
899-46-2035
998-72-3567

(19 row(s) affected)



重要 涉及 DISTINCT 的语句的输出取决于列的排序规则或应用 DISTINCT 的表达式。有关不同排序规则的效果的更多信息,请参见 SQL Server 排序规则基础知识。


对于 DISTINCT 关键字来说,各空值将被认为是相互重复的内容。当 SELECT 语句中包括 DISTINCT 时,不论遇到多少个空值,在结果中只返回一个 NULL。
whb147 2003-12-25
  • 打赏
  • 举报
回复
你在sql里面可以实现的话,在asp里就可以。
xtyqzp 2003-12-25
  • 打赏
  • 举报
回复
不知你在不在,我们可以讨论一下。
我的考虑是:
sqlstr="select biaoti distinct from up2"
但含上述语句的ASP代码连编译都通不过。
xtyqzp 2003-12-25
  • 打赏
  • 举报
回复
我也有同样的问题啊!
郁闷了才来CSDN的。
一起等!!!!!!!!!!!!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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