日期:2014-05-16  浏览次数:20821 次

网页中如何按照发帖时间顺序显示该文章所在栏目的超链接,并且栏目不重复
本帖最后由 zhrobin 于 2013-01-10 21:08:26 编辑
sub mynews(a,b)
        response.Write("<table width=96% border=0 cellspacing=0 cellpadding=0>")
set rs=server.CreateObject("adodb.recordset")
sql="select top 7 * from yalist where yaType=2 and fromid="&a&" order by norder desc, id desc"
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
        response.Write("<tr>")
        response.Write("<td class=3h><img src=images/5ice.gif width=5 height=5 hspace=5>")
set rst=conn.execute("select * from yaType where yaType=2 and id="&rs("nType")&"")
if not rst.eof then
response.write("<font color=#006600>【<a target=_blank href=article.asp?ntype="&rst("fromid")&"&fromid="&rs("ntype")&" >"&rst("typename")&"</a>】</font>")
end if
rst.close



部分代码如上,
yalist 是文章列表,yatype 为栏目列表,两个表通过ID号相连,yatype在两个表中都表示所选范围在同一大类别。

这段代码的输出效果为,部门A共a,b,c三个分栏目的7篇文章按顺序排列,这个时候这7篇文章所在的分栏目a,b,c肯定会重复显示,如何分别只显示a,b,c一次。

------解决方案--------------------
那就是 分组group by一下,取最大的
select a,max(b) ,max(c) from table group by a order by a