我想跟踪访问我网站的IP地址。我想知道他们访问的时间和页面。我在VISITORIP中存储了ip地址,在DATEENTERED中输入了日期,在HTTPADDRESS列中存储了页面URL。
我想按日期对它们进行分组。我的结果应该是:
TIME PAGE
7/12/2009
3:16:27 PM ?Section=products&SubSection=products&CATEGORYID=1
2:46:50 PM ?Section=products&SubSection=products&CATEGORYID=8
2:20:45 PM ?Section=products&SubSection=products&CATEGORYID=11
7/11/2009
9:34:28 AM ?Section=products&SubSection=products&CATEGORYID=7
9:33:31 AM ?Section=products&SubSection=products&CATEGORYID=2
7/10/2009
9:53:16 PM ?Section=products&SubSection=products&CATEGORYID=9
9:34:14 PM ?Section=products&SubSection=products&CATEGORYID=4
9:27:11 PM ?Section=products&SubSection=products&CATEGORYID=3
9:15:47 PM ?Section=products&SubSection=products&CATEGORYID=15
问题是,我无法按日期对它们进行分组。我得到的结果是:
07/12/2009
7/12/2009 3:16:27 PM /html/default.aspProcess=HomeNewSeason&IMAGECONTENT=bg_home_newtaste.gif
7/12/2009 3:16:27 PM /html/default.aspProcess=HomeBestSeller&IMAGECONTENT=bg_home_customerschoice.gif
07/12/2009
7/12/2009 3:16:27 PM /html/default.aspProcess=HomeNewSeason&IMAGECONTENT=bg_home_newtaste.gif
7/12/2009 3:16:27 PM /html/default.aspProcess=HomeBestSeller&IMAGECONTENT=bg_home_customerschoice.gif
07/09/2009
7/9/2009 5:37:02 PM /html/default.aspSection=checkout
07/09/2009
7/9/2009 5:37:02 PM /html/default.aspSection=checkout
07/09/2009
7/9/2009 5:37:02 PM /html/default.aspSection=checkout
我的代码:
<%
Case "TrackIP"
IPADDRESS = Request.QueryString("IPADDRESS")
SQL = "SELECT CONVERT(VARCHAR(10), DATEENTERED, 101) AS DATEENTERED"
SQL = SQL & " FROM STATS"
SQL = SQL & " WHERE VISITORIP = '"& IPADDRESS &"'"
SQL = SQL & " GROUP BY DATEENTERED"
SQL = SQL & " ORDER BY DATEENTERED DESC"
Set objDateEntered = objConn.Execute(SQL)
%>
<table>
<thead>
<tr>
<th>Time</th>
<th>Page</th>
</tr>
</thead>
<tbody>
<% Do While Not objDateEntered.EOF %>
<tr class="row-title">
<td colspan="2"><%=objDateEntered("DATEENTERED")%></td>
</tr>
<%
SQL = "WITH LASTVISIT AS ("
SQL = SQL & " SELECT VISITORIP, MAX(DATEENTERED) AS DATEENTERED"
SQL = SQL & " FROM STATS"
SQL = SQL & " WHERE VISITORIP = '"& IPADDRESS &"' AND CONVERT(VARCHAR(10), DATEENTERED, 101) = CONVERT(VARCHAR(10), '"& objDateEntered("DATEENTERED") &"', 101)"
SQL = SQL & " GROUP BY VISITORIP"
SQL = SQL & " )"
SQL = SQL & " SELECT STATS.VISITORIP, STATS.HTTPADDRESS, STATS.DATEENTERED"
SQL = SQL & " FROM STATS"
SQL = SQL & " INNER JOIN LASTVISIT"
SQL = SQL & " ON LASTVISIT.VISITORIP = STATS.VISITORIP AND LASTVISIT.DATEENTERED = STATS.DATEENTERED"
SQL = SQL & " ORDER BY STATS.DATEENTERED DESC"
Set objTrackIP = objConn.Execute(SQL)
%>
<% Do While Not objTrackIP.EOF %>
<tr class="row-a">
<td><%=objTrackIP("DATEENTERED")%></td>
<td class=""><%=objTrackIP("HTTPADDRESS")%></td>
</tr>
<%
objTrackIP.MoveNext
Loop
%>
<%
objDateEntered.MoveNext
Loop
%>
</tbody>
</table>
编辑:我认为问题在于我的外部查询。但我把它们按DATEENTERED字段分组,我不知道还能做什么。
答案 0 :(得分:1)
第一个查询应该是
"SELECT
DISTINCT CONVERT(VARCHAR(10), DATEENTERED, 101) AS vDATE
FROM
STATS
WHERE
VISITORIP = '"& IPADDRESS &"'"
ORDER BY
DATEENTERED DESC"
然后打印vData列
和第二个SQL
SELECT
VISITORIP, HTTPADDRESS, CONVERT(VARCHAR(8), DATEENTERED, 8) AS vTIME
FROM
STATS
WHERE
CONVERT(VARCHAR(10), DATEENTERED, 101) = '" & objDateEntered("vDATE") &"'
AND VISITORIP = '"& IPADDRESS &"'
ORDER BY VISITORIP ASC, DATEENTERED DESC
我认为这会解决问题..
答案 1 :(得分:0)
问题出在下一个代码行中:
SELECT CONVERT(VARCHAR(10), DATEENTERED, 101) AS DATEENTERED
然后按此日期分组
GROUP BY DATEENTERED
ORDER BY DATEENTERED DESC
您可以通过varchar进行分组和排序。 我认为,当你将它转换为ro varchar时,你需要使用另一个别名,但是你确实需要按dateenter类型命名。
答案 2 :(得分:0)
如果您想要使用Google Analytics这样的内容,那么您是否试图让某些访问者跟踪发生?