当前位置: 数据库>sqlserver
sql语句实例 统计页面链接的sql语句
来源: 互联网 发布时间:2014-08-29
本文导语: 例1,统计包含0个链接的页面 代码示例: SELECT page_namespace, page_title FROM page LEFT JOIN pagelinks ON pl_from = page_id WHERE pl_namespace IS NULL LIMIT 1; 说明: 仅统计包含0个链接的网页,不会统计包括 图像链接、模板链接、分类链接...
例1,统计包含0个链接的页面
代码示例:
SELECT
page_namespace,
page_title
FROM page
LEFT JOIN pagelinks
ON pl_from = page_id
WHERE pl_namespace IS NULL
LIMIT 1;
page_namespace,
page_title
FROM page
LEFT JOIN pagelinks
ON pl_from = page_id
WHERE pl_namespace IS NULL
LIMIT 1;
说明: 仅统计包含0个链接的网页,不会统计包括 图像链接、模板链接、分类链接以及外部链接的页面。
例2,统计包含0个链接的页面
代码示例:
SELECT
page_namespace,
page_title
FROM page
LEFT JOIN pagelinks
ON pl_title = page_title
AND pl_namespace = page_namespace
WHERE pl_namespace IS NULL
LIMIT 1;
page_namespace,
page_title
FROM page
LEFT JOIN pagelinks
ON pl_title = page_title
AND pl_namespace = page_namespace
WHERE pl_namespace IS NULL
LIMIT 1;
说明: 统计0链接页面。
例3,取得作者名称,包括用户页面及重定向页面
代码示例:
SELECT
CONCAT(ns_name, ':', page_title),
page_len
FROM page
JOIN toolserver.namespace
ON page_namespace = ns_id
AND dbname = 'enwiki_p'
LEFT JOIN templatelinks
ON tl_from = page_id
WHERE page_len < 50
AND page_is_redirect = 0
AND page_namespace NOT IN (2, 3)
AND tl_from IS NULL
AND (SELECT
COUNT(DISTINCT rev_user_text)
FROM revision
WHERE rev_page = page_id) = 1
ORDER BY page_len ASC
CONCAT(ns_name, ':', page_title),
page_len
FROM page
JOIN toolserver.namespace
ON page_namespace = ns_id
AND dbname = 'enwiki_p'
LEFT JOIN templatelinks
ON tl_from = page_id
WHERE page_len < 50
AND page_is_redirect = 0
AND page_namespace NOT IN (2, 3)
AND tl_from IS NULL
AND (SELECT
COUNT(DISTINCT rev_user_text)
FROM revision
WHERE rev_page = page_id) = 1
ORDER BY page_len ASC
说明: 将呈现一个包含作者信息的列表页面,包括用户页面与重定向页面中的信息。