关于asp记要统计出现结果重复,高手支招~

关于asp记录统计出现结果重复,高手支招~!HTML code table width98% border0 aligncenter cellpa

关于asp记录统计出现结果重复,高手支招~!

HTML code
 <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">  <tr>    <th height=25 colspan="3" class="tableHeaderText">&nbsp;</th>  </tr>        <tr class="tableHeaderText" height=25>          <td width="155" align="center"><b>区县名称</b></td>          <td width="653" align="center"><b>学校名称</b></td>          <td width="177" align="center"><b>到校人数</b></td>        </tr>        <%set rsy=conn.execute("select * from  t_tdd where m_bmdw="""&qu_dm&""" order by m_id asc")      if not rsy.eof then      do while not rsy.eof      zxmc=rsy("m_zxmc")      %>                    <%set rsq=conn.execute("select count(*) as numq from t_tdd where m_bmdw="""&qu_dm&""" and m_zxmc="""&zxmc&"""")        numq=rsq("numq")        %>                                    <tr onMouseOver="this.style.background='#FFFFCC'" onMouseOut="this.style.background='#EEF7FD'">          <td align="center"><%=s_mc%></td>          <td align="center"><%=zxmc%></td>          <td align="center"><%=numq%></td>        </tr>      <%rsy.movenext        loop        end if%>            <tr >    <td height="25" colspan="3" aligh="right">&nbsp;</td>  </tr></table>




代码如上,我本来的意思是统计每个区县每个学校到校的学生有好多,数据统计是没问题,就是显示出来的数据时重复的,比如

渝中区 实验小学 2人
渝中区 实验小学 2人
渝中区 第一小学 3人
渝中区 第一小学 3人
渝中区 第一小学 3人

有几个人,数据就会重复几次,请大家帮我看下代码,是什么地方的问题~!

[解决办法]
select distinct s_mc,zxmc from t_tdd where m_bmdw="""&qu_dm&""" order by m_id asc



[解决办法]
一楼正解,问题出在你第一句的查询
<%set rsy=conn.execute("select * from t_tdd where m_bmdw="""&qu_dm&""" order by m_id asc")
这一句没有去除重复,循环出来的结果就有重复,所以在select 后面添加个distinct m_zxmc就可以去掉m_zxmc字段的重复数据,具体可百度select distinct。另外我建议如果只是用到一两个字段的内容,没有必要用select * ,小应用还没问题,但养成好习惯还是好的