Toggle navigation
Home
New Query
Recent Queries
Discuss
Database tables
Database names
MediaWiki
Wikibase
Replicas browser and optimizer
Login
History
Fork
This query is marked as a draft
This query has been published
by
Nettrom
.
Counting links pointing to a given set of articles. Now also counts links to redirects pointing to the given article. FIXME: the redirect version needs testing in case an article has no redirects
Toggle Highlighting
SQL
USE enwiki_p; SELECT p.page_id AS ilc_page_id, COUNT(*) AS ilc_numlinks FROM page p JOIN pagelinks pl ON (p.page_namespace=pl.pl_namespace AND p.page_title =pl.pl_title) JOIN page p2 ON pl.pl_from=p2.page_id WHERE p.page_id IN (12, 25, 39, 53, 290, 303, 305, 307, 308, 309) AND p2.page_namespace=0 GROUP BY p.page_id; SELECT page_id, links.numlinks + redirlinks.numlinks - redirs.numredirs AS numlinks FROM (SELECT p.page_id AS page_id, count(*) AS numlinks FROM page p JOIN pagelinks pl ON (p.page_namespace=pl.pl_namespace AND p.page_title=pl.pl_title) WHERE p.page_id IN (316, 324, 325, 330, 332, 334, 336, 339, 340, 344) AND pl.pl_from_namespace=0 GROUP BY p.page_id ) AS links JOIN (SELECT p1.page_id, count(*) AS numredirs FROM page p1 JOIN redirect ON (p1.page_namespace=rd_namespace AND page_title=rd_title) JOIN page p2 ON rd_from=p2.page_id WHERE p2.page_namespace=0 AND p1.page_id IN (316, 324, 325, 330, 332, 334, 336, 339, 340, 344) GROUP BY page_id ) AS redirs USING (page_id) JOIN (SELECT p1.page_id, count(*) AS numlinks FROM page p1 JOIN redirect ON (p1.page_namespace=rd_namespace AND page_title=rd_title) JOIN page p2 ON rd_from=p2.page_id JOIN pagelinks pl ON (p2.page_namespace=pl.pl_namespace AND p2.page_title=pl.pl_title) WHERE p2.page_namespace=0 AND pl.pl_from_namespace=0 AND p1.page_id IN (316, 324, 325, 330, 332, 334, 336, 339, 340, 344) GROUP BY page_id ) AS redirlinks USING (page_id);
By running queries you agree to the
Cloud Services Terms of Use
and you irrevocably agree to release your SQL under
CC0 License
.
Submit Query
Stop Query
All SQL code is licensed under
CC0 License
.
Checking query status...