User:Reosarevok/Wikidata Example Queries: Difference between revisions

From MusicBrainz Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 40: Line 40:




[https://query.wikidata.org/#%23Composers%20who%20don%27t%20have%20a%20MusicBrainz%20ID%20stored%2C%20sorted%20by%20number%20of%20compositions%0ASELECT%20%28COUNT%28%3Fcomposition%29%20AS%20%3Fcount%29%20%3FcomposerLabel%20%3Fcomposer%20%0AWHERE%20%7B%20%0A%20%20%20%20%3Fcomposer%20wdt%3AP106%20wd%3AQ639669%20.%0A%20%20%09MINUS%20%7B%20%3Fcomposer%20wdt%3AP434%20%5B%5D%20%7D%20.%0A%20%20%20%20%7B%0A%20%20%20%20SELECT%20%3Fcomposer%20%28COUNT%28%3Fcomposition%29%20AS%20%3Fcount%29%0A%20%20%20%20WHERE%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%3Fcomposition%20wdt%3AP86%20%3Fcomposer%20.%0A%20%20%20%20%7D%0A%20%20%20%20GROUP%20BY%20%3Fcomposer%20%7D%0A%20%20%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%0A%7D%0AORDER%20BY%20DESC%28%3Fcount%29 People who have composed at least one work that is in Wikidata and have no MBIDs, sorted by number of works]
[https://query.wikidata.org/#%23Composers%20who%20don%27t%20have%20a%20MusicBrainz%20ID%20stored%2C%20sorted%20by%20number%20of%20compositions%0ASELECT%20%28COUNT%28%3Fcomposition%29%20AS%20%3Fcount%29%20%3FcomposerLabel%20%3Fcomposer%20%0AWHERE%20%7B%20%0A%20%20%20%20%3Fcomposition%20wdt%3AP86%20%3Fcomposer%20.%0A%20%20%20%20%3Fcomposer%20wdt%3AP106%20wd%3AQ639669%20.%0A%20%20%09MINUS%20%7B%20%3Fcomposer%20wdt%3AP434%20%5B%5D%20%7D%20.%0A%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%0A%20%20%7D%0AGROUP%20BY%20%3FcomposerLabel%20%3Fcomposer%0AORDER%20BY%20DESC%28%3Fcount%29 People who have composed at least one work that is in Wikidata and have no MBIDs, sorted by number of works]
<nowiki>
<nowiki>
SELECT ?composer ?composerLabel ?count
SELECT (COUNT(?composition) AS ?count) ?composerLabel ?composer
WHERE
WHERE {
?composition wdt:P86 ?composer .
{
?composer wdt:P106 wd:Q639669 .
{
SELECT ?composer (COUNT(?composition) AS ?count)
MINUS { ?composer wdt:P434 [] } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
WHERE
{
?composition wdt:P86 ?composer;
MINUS { ?composer wdt:P434 [] } .
}
GROUP BY ?composer
}
}
GROUP BY ?composerLabel ?composer
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)
ORDER BY DESC(?count)
</nowiki>
</nowiki>

Revision as of 13:06, 3 November 2017

These are example queries for the Wikidata SPARQL endpoint


All composers who don't have a MusicBrainz ID stored

For "musicians" instead of "composers", change Q36834 to Q639669.

SELECT ?entityLabel ?entity {
	?entity wdt:P106 wd:Q36834 .
  	MINUS { ?entity wdt:P434 [] } .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}


Female composers who don't have a MusicBrainz ID stored

SELECT ?entityLabel ?entity {
	?entity wdt:P106 wd:Q36834 .
	?entity wdt:P21 wd:Q6581072 .
  	MINUS { ?entity wdt:P434 [] } .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}


Composers born somewhere in Germany who don't have a MusicBrainz ID stored

SELECT ?entityLabel ?entity {
	?entity wdt:P106 wd:Q36834 .
  	?entity wdt:P19 ?place .
    ?place wdt:P17 wd:Q183 .
  	MINUS { ?entity wdt:P434 [] } .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
 


People who have composed at least one work that is in Wikidata and have no MBIDs, sorted by number of works

SELECT (COUNT(?composition) AS ?count) ?composerLabel ?composer 
WHERE { 
    ?composition wdt:P86 ?composer .
    ?composer wdt:P106 wd:Q639669 .
  	MINUS { ?composer wdt:P434 [] } .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  }
GROUP BY ?composerLabel ?composer
ORDER BY DESC(?count)
 


Operas that don't have a MusicBrainz ID stored

SELECT ?entityLabel ?entity {
	?entity wdt:P31 wd:Q1344 .
  	MINUS { ?entity wdt:P435 [] } .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}