构建sql sql语法

发布于 2024-09-28 06:34:40 字数 1993 浏览 3 评论 0原文

+----+--------------+------+--------+---------+---------------------+-----------
| Id | ip           | uri  | status | browser | time                |refer   ..........
+----+--------------+------+--------+---------+---------------------+-----------
int    varchar       varchar int     varchar   timeStampe            varchar  ..........
-------------------------------------------------------------------------------

这是我的表的结构,用于保存tomcat日志(模式是组合)。

现在我想做一些类型的统计,但是我不擅长sql语句,所以我在这里问。

统计类型为:

1)查询同一时刻哪些页面被请求最多。然后我想将它们显示在表格中。 2)查询同一时刻哪些文件被请求最多。然后我想将它们显示在表格中。 3)查询访客从哪里(引用)跳转到网站,并对引用进行排序。

更新

日志示例:

127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /tomcat.gif HTTP/1.1" 200 1934 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /asf-logo-wide.gif HTTP/1.1" 200 5866 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /tomcat-power.gif HTTP/1.1" 200 2324 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /favicon.ico HTTP/1.1" 200 21630 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:46 +0800] "GET /manager/html HTTP/1.1" 401 1833 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:49 +0800] "GET /manager/status HTTP/1.1" 401 1833 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"

/tomcat.gif /asf-logo-wide.gif 是文件。

/manager/status /manager/html 是页面。

+----+--------------+------+--------+---------+---------------------+-----------
| Id | ip           | uri  | status | browser | time                |refer   ..........
+----+--------------+------+--------+---------+---------------------+-----------
int    varchar       varchar int     varchar   timeStampe            varchar  ..........
-------------------------------------------------------------------------------

This is the structure of my table used to save the tomcat logs(pattern is combine) here.

Now I want to do some types of statistics,however I am not good at sql words,so I ask it here.

statistics type is:

1) query which pages are requested most at a same monment. Then I want to show them in a table.
2)query which files are requested most at a same monment. Then I want to show them in a table.
3)query from where (the refer )visitor jump to the site,sort the refers.

update

THe example of the log:

127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /tomcat.gif HTTP/1.1" 200 1934 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /asf-logo-wide.gif HTTP/1.1" 200 5866 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /tomcat-power.gif HTTP/1.1" 200 2324 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:43 +0800] "GET /favicon.ico HTTP/1.1" 200 21630 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:46 +0800] "GET /manager/html HTTP/1.1" 401 1833 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
127.0.0.1 - - [19/Oct/2010:20:38:49 +0800] "GET /manager/status HTTP/1.1" 401 1833 "http://localhost:9000/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"

The /tomcat.gif /asf-logo-wide.gif are files.

/manager/status /manager/html are pages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罗罗贝儿 2024-10-05 06:34:40

1)查询同一时刻哪些页面被请求最多。

SELECT time, uri, count(1) 
FROM tableName 
GROUP BY time, uri 
ORDER BY 3 DESC

2)查询同一时刻哪些文件被请求最多。

- Not sure how this is different from Query 1

3) 对于特定的 URI,这将为您提供最受欢迎的引用站点。 (这就是你所要求的,如果我理解正确的话)

SELECT uri, refers, count(1) 
FROM tableName 
GROUP BY uri, refers 
ORDER BY 3 DESC

1)Query which pages are requested most at a same moment.

SELECT time, uri, count(1) 
FROM tableName 
GROUP BY time, uri 
ORDER BY 3 DESC

2)Query which files are requested most at a same moment.

- Not sure how this is different from Query 1

3) For a particular URI, this will give you the most popular referring sites. (this is what you are asking for, IF i have understood correctly)

SELECT uri, refers, count(1) 
FROM tableName 
GROUP BY uri, refers 
ORDER BY 3 DESC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文