现在我想过滤重复记录,这个函数 Show_NewHire 我想过滤重复的companyname 只显示第一个companyname以后重复的都不显示 这句 sqlh="Select Top "& topNum &" * From job_c_hire Where hire_status=1 and hire_enddate>getdate() order by hire_announcedate desc" 应该怎么改?
Sub Show_NewHire(topNum,Len1,Len2) Dim rsh,sqlh Set rsh=Server.CreateObject("ADODB.RecordSet") sqlh="Select Top "& topNum &" * From job_c_hire Where hire_status=1 and hire_enddate>getdate() order by hire_announcedate desc" rsh.Open sqlh,conn,1,1 If Not(rsh.Eof) Then %> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <% i=1 Do While Not rsh.Eof hire_place=left(rsh("hire_place"),Len1) company_name=left(rsh("hire_comname"),Len2) if rsh("hire_command")=1 then company_name=" <font color=""#FF0000"">"&company_name&" </font>" end if if i mod 2=0 then %> <tr bgcolor='#FFFFFF'> <% else response.write " <tr bgcolor='#FFFFFF'>"& vbcrlf end if%> <td width="20" height="20"> <img src="images/tp0011.gif" width="9" height="15" border="0"> </td> <td> <%If rsh("hire_cmember") <>"" and rsh("company_id") <>"" Then%> <a href="Enterprise/Enterprise_JOB.asp?id= <%=rsh("company_id")%>" target="_blank"> <font color="000099"> <%=company_name%> </a> <%Else%> <%=company_name%> <%End If%> ( <%=rsh("hire_number")%>人) <%if datevalue(rsh("hire_announcedate"))=date() then%> <img src="../images/new.gif"> <%end if%> </td> </tr> <% rsh.MoveNext i=i+1 Loop %> </table> <% End If rsh.Close Set rsh=Nothing End Sub
select Top "& topNum &" * From job_c_hire as a Where hire_status=1 and hire_enddate>getdate() (select count(*) from job_c_hire where companyname=a.companyname and id>a.id) < 1 order by hire_announcedate desc
用group by companyname来实现,其他的select字段可用max聚合函数,如: sqlh="Select max(hire_place) as hire_place,companyname From job_c_hire Where hire_status=1 and hire_enddate>getdate() group by companyname order by hire_announcedate desc"
Select*From job_c_hire c Where id in (selecttop1 id from job_c_hire where hire_status=1and hire_enddate>getdate() and hire_comname=c.hire_comname orderby hire_announcedate desc) orderby hire_announcedate desc
Select * From job_c_hire c Where companyname ,announcedate in (select companyname ,max(announcedate) from job_c_hire where hire_status=1 and hire_enddate> getdate() group by companyname ) order by hire_announcedate desc
Select * From job_c_hire c Where (companyname ,announcedate) in --这里忘加括号了 (select companyname ,max(announcedate) from job_c_hire where hire_status=1 and hire_enddate> getdate() group by companyname ) order by hire_announcedate desc
select Top "& topNum &" a.* from hire_announcedate a where xxx = (select top 1 xxx from hire_announcedate where companyname = a.companyname) order by a.hire_announcedate desc