Fork of Most linked disambiguations in cswiki (with redirects!) by Matěj Suchánek
This query is marked as a draft This query has been published by Edoderoo.

SQL

AخA
 
USE nlwiki_p;
SELECT disambigs.page_title, COUNT(DISTINCT links.pl_from) AS direct_links, COUNT(DISTINCT redirects.page_id) AS redirects,
    COUNT(DISTINCT links.pl_from) + COUNT(DISTINCT links_to_redirects.pl_from) AS all_backlinks
    FROM (SELECT * FROM page_props WHERE pp_propname = 'disambiguation') AS disambigs
    JOIN page AS disambigs
        ON disambigs.page_id = pp_page
    JOIN (SELECT * FROM pagelinks WHERE pl_from_namespace = 0 OR pl_from_namespace = 14) AS links
        ON links.pl_title = disambigs.page_title AND links.pl_namespace = disambigs.page_namespace
    LEFT JOIN page AS redirects
        ON redirects.page_is_redirect = 1 AND redirects.page_id = links.pl_from AND redirects.page_namespace = disambigs.page_namespace
    LEFT JOIN (SELECT * FROM pagelinks WHERE pl_from_namespace = 0) AS links_to_redirects
        ON links_to_redirects.pl_title = redirects.page_title AND links_to_redirects.pl_namespace = redirects.page_namespace
GROUP BY disambigs.page_title
ORDER BY all_backlinks DESC, direct_links DESC, redirects, disambigs.page_title
LIMIT 1000;
By running queries you agree to the Cloud Services Terms of Use and you irrevocably agree to release your SQL under CC0 License.
All SQL code is licensed under CC0 License.

Checking query status...