Help:Query examples

From Parasports
Jump to: navigation, search

Query engine is available at https://query.para-sports.es/#query .

Contents

People

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#people
SELECT ?item ?itemLabel
WHERE

{
    ?item wdt:P2 wd:Q3 .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Sportswomen from Spain

This example includes date of birth, where available, for Spanish sportswomen.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Spanish women sportspeople
SELECT ?item ?itemLabel ?itemDescription ?dob
WHERE
{
	?item wdt:P119 wd:Q2986 .
	?item wdt:P150 wd:Q1073 .
	?item wdt:P185 wd:Q2988 .
	?item wdt:P2 wd:Q3 .
	OPTIONAL { ?item wdt:P130 ?dob }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

total men and women on ParaSport

This example counts the total number of men versus women who have male or female in sex or gender field on their item page and displays it as a bar graph.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Count of total entries for men versus women
#defaultView:BarChart
SELECT ?maleorfemaleLabel (COUNT(?gender) AS ?count)
WHERE
{
  ?gender wdt:P185 ?maleorfemale.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?maleorfemaleLabel
ORDER BY ?maleorfemaleLabel

Parasportsperson type

This example counts the total number of people based on the type of disability type of disability listed field on their item page and displays it as a bubble chart.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Type of disability
#defaultView:BubbleChart
SELECT ?cid ?type (count(*) as ?count)
WHERE
{
	?pid wdt:P2 wd:Q3 .
	?pid wdt:P191 ?cid .
	OPTIONAL {
		?cid rdfs:label ?type filter (lang(?type) = "en") .
	}
}
GROUP BY ?cid ?type
ORDER BY DESC(?count) ASC(?type)

Iranian sportspeople

This example provides a list of Iranian sportspeople, and details where available about them including date of birth, gender, disability, classification, Paralympic Games participation, and if they were a flag bearer.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Iranian sportspeople
SELECT ?item ?itemLabel ?itemDescription  ?dob ?dobLabel ?gender ?genderLabel ?disability ?disabilityLabel ?classification ?classificationLabel ?gamesparticipation ?gamesparticipationLabel ?flagbearer ?flagbearerLabel
WHERE
{
	?item wdt:P119 wd:Q2986 .
	?item wdt:P150 wd:Q960 .
	OPTIONAL { ?item wdt:P130 ?dob }  
	OPTIONAL { ?item wdt:P185 ?gender }  
	OPTIONAL { ?item wdt:P191 ?disability }  
	OPTIONAL { ?item wdt:P28 ?classification }  
	OPTIONAL { ?item wdt:P196 ?gamesparticipation }  
	OPTIONAL { ?item wdt:P608 ?flagbearer }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}


Wheelchair curlers

This example provides a list of wheelchair curlers, their gender and references for their gender.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
prefix pp: <http://para-sports.es/prop/P>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>

#wheelchair curlers
SELECT ?item ?itemLabel ?genderLabel ?gender_reference_URL ?gender_reference_siteLabel
WHERE
{	?item wdt:P31 wd:Q2479 .
	OPTIONAL { ?item wdt:P185 ?gender } # gender
    
    OPTIONAL { ?item pp:185/prov:wasDerivedFrom/pr:P127 ?gender_reference_URL. }
    OPTIONAL { ?item pp:185/prov:wasDerivedFrom/pr:P143 ?gender_reference_site. }
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try it

Average age disability acquired by how acquired

This example shows the average age of people based on their age in years when they acquired by disability based on how they acquired their disability.

prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

SELECT ?disabilityacquired ?disabilityacquiredLabel (AVG(?ageacquired) AS ?avgAgeacquired)
WHERE
{
  ?person wdt:P192 ?disabilityacquired;
        wdt:P762 ?ageacquired.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?disabilityacquired ?disabilityacquiredLabel
HAVING(COUNT(?disabilityacquired) > 0)
ORDER BY DESC(?avgAgeacquired)
}

try it


Emigrated from and immigrated to

List of people who have moved from one country to the next, with optional disability type and sport played information if available.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Emigrated and Immigrated
SELECT ?person ?personLabel ?emigratedLabel ?immigratedLabel ?disabilityLabel ?sportLabel
WHERE
{
	?person wdt:P764 ?emigrated . 
	?person wdt:P765 ?immigrated .
	OPTIONAL { ?person wdt:P191 ?disability }  
  	OPTIONAL { ?person wdt:P31 ?sport }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try


Immigration extended

List of people who have moved from one country to the next, with optional disability type and sport played information if available.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Emigrated and Immigrated
SELECT ?person ?personLabel ?emigratedLabel ?immigratedLabel ?immigratedwhenLabel ?startedsportwhenLabel ?reasonLabel ?yearimmigrated ?sportsLabel
WHERE
{
	?person wdt:P764 ?emigrated . 
	?person wdt:P765 ?immigrated .
  	OPTIONAL { ?person wdt:P1039 ?immigratedwhen }  
  	OPTIONAL { ?person wdt:P1043 ?startedsportwhen }  
	OPTIONAL { ?person wdt:P767 ?reason }  
  	OPTIONAL { ?person wdt:P679 ?yearimmigrated }  
  	OPTIONAL { ?person wdt:P766 ?ageimmigrated }  
  	OPTIONAL { ?person wdt:P31 ?sports }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try

Number of sportspeople by country

Below is a count of the total sportspeople by country. This is useful for getting an idea of the relative completeness of some of these datasets.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Number of female sportspeople by country

SELECT ?cid ?country (count(*) as ?count)
WHERE
{
	?pid wdt:P119 wd:Q2986 .
	?pid wdt:P150 ?cid .
  
	OPTIONAL {
		?cid rdfs:label ?country filter (lang(?country) = "en") .
	}
}
GROUP BY ?cid ?country
ORDER BY DESC(?count) ASC(?country)


Number of sportswomen by country

Below is a count of the total female sportspeople by country. This is useful for getting an idea of the relative completeness of some of these datasets.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Number of female sportspeople by country

SELECT ?cid ?country (count(*) as ?count)
WHERE
{
	?pid wdt:P119 wd:Q2986 .
    ?pid wdt:P185 wd:Q2988 .
	?pid wdt:P150 ?cid .
  
	OPTIONAL {
		?cid rdfs:label ?country filter (lang(?country) = "en") .
	}
}
GROUP BY ?cid ?country
ORDER BY DESC(?count) ASC(?country)

Date of birth

Oldest sportspeople : Date of birth

Some of these people may have died. This is based on birthdays, not year of birth.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Oldest Paralympians
SELECT ?paralympian ?paralympianLabel ?date (ROUND((NOW() - ?date)/365.2425) AS ?age)
{
  ?paralympian wdt:P119 wd:Q2986.
  OPTIONAL { ?paralympian wdt:P130 ?date. }
  FILTER(BOUND(?date)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date
LIMIT 100

Oldest sportspeople : Date of birth

This one uses year of birth with P194 as opposed to P130 for date of birth. It calculates age based on year of birth, which is much more commonly used in IPC records.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Oldest Paralympians
SELECT ?paralympian ?paralympianLabel ?date (ROUND((NOW() - ?date)/365.2425) AS ?age)
{
  ?paralympian wdt:P119 wd:Q2986.
  OPTIONAL { ?paralympian wdt:P194 ?date. }
  FILTER(BOUND(?date)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date
LIMIT 100


Timline : Australian Women Date of birth

This one uses P2, P150, P185 coupled with P130 to create a visual timeline of Australian women's date of birth. If it doesn't have limits to bring the total display to less than 100 people, it crashes from slowness.


prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

#defaultView:Timeline
SELECT ?person ?personLabel ?date
WHERE
{
  ?person wdt:P2 wd:Q3;
          wdt:P150 wd:Q132;
          wdt:P185 wd:Q2988;
          wdt:P130 ?date.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date

Paralympic Games

List of Paralympic Games by year

This is a simple list of Summer Paralympic Games by year.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#defaultView:Timeline
SELECT ?item ?itemLabel ?gamesdate
WHERE
{
	?item wdt:P2 wd:Q1142 .
    ?item wdt:P38 ?gamesdate .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel ?gamesdate

Count of medals Games by year

PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

#defaultView:LineChart

SELECT DISTINCT ?date (COALESCE(?paralympicmedals, ?deaflympicmedals, 0) as ?medals) WHERE {
    ?item wdt:P2 wd:Q63341 . # That are in some collection
  	OPTIONAL { ?item wdt:P995 ?deaflympicmedals }
  	OPTIONAL { ?item wdt:P436 ?paralympicmedals }
  	?item wdt:P165/wdt:P165 wd:Q957.
    ?item wdt:P184 ?date.
 	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try


Disability acquired

A count of the different ways people are known to have acquired their disabilities for people at the 2018 Winter Paralympics.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Count of total types of ways disability acquired for 2018 Winter Paralympians
#defaultView:BarChart
SELECT ?disabilityacquiredLabel (COUNT(?disability) AS ?count)
WHERE
{
  ?disability wdt:P196  wd:Q2771 .
  ?disability wdt:P192 ?disabilityacquired.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?disabilityacquiredLabel
ORDER BY ?disabilityacquiredLabel

try it


Disability acquired

A count of the different ways people are known to have acquired their disabilities by Paralympic Games.

prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

#Paralympians by Games year and disability type
#defaultView:TreeMap
SELECT ?games ?disabilityEditionLabel (COUNT(?person) as ?count)
WHERE
{
	?person wdt:P196 ?gamesEdition.
    ?person wdt:P192 ?disabilityEdition.
    ?gamesEdition rdfs:label ?gamesEditionLabel.
    FILTER((LANG(?gamesEditionLabel)) = "en")
    BIND(CONCAT(?gamesEditionLabel, " edition") AS ?games)
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?games ?disabilityEditionLabel

try it

List of types of disabilities

A list of the types of disabilities for competitors at the Paralympic Games.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#List of Paralympians by Games and disability
SELECT  ?itemLabel ?itemDescription ?gamesEditionLabel ?disabilityEditionLabel
WHERE
{
	?item wdt:P196 ?gamesEdition.
    ?item wdt:P191 ?disabilityEdition.
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try it


List of 2018 Winter Paralympians

A list of the 2018 Winter Paralympians.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#List of Paralympians by Games and disability
SELECT  ?itemLabel ?itemDescription
WHERE
{
	?item wdt:P196  wd:Q2771.
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

try it


Count of 2018 Winter Paralympians by year of birth

Count of 2018 Winter Paralympians by year of birth

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Count of total types of ways disability acquired for 2018 Winter Paralympians
#defaultView:BarChart
SELECT ?yearofbirth (COUNT(?disability) AS ?count)
WHERE
{
  ?disability wdt:P196  wd:Q2771 .
  ?disability wdt:P194 ?yearofbirth.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?yearofbirth
ORDER BY ?yearofbirth

try it

Activity by year

This is a simple list of the number of sportspeople by citizenship active per year.


prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>


#defaultView:LineChart
SELECT ?year (COUNT(?_country) AS ?count)  (SAMPLE(?_countryLabel) AS ?_countryLabel)  WHERE {
  ?item wdt:P119 wd:Q2986.
  ?item wdt:P203 ?_date.
  ?item wdt:P150 ?_country.
  ?_country rdfs:label ?_countryLabel.
  BIND(str(YEAR(?_date)) AS ?year)
  FILTER((LANG(?_countryLabel)) = "en")
  FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_countryLabel ?year
HAVING (?count > 10)

active by class by year

prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>


#defaultView:LineChart
SELECT ?year (COUNT(?_classification) AS ?count)  (SAMPLE(?_classificationLabel) AS ?_classificationLabel)  WHERE {
  ?item wdt:P119 wd:Q2986.
  ?item wdt:P203 ?_date.
  ?item wdt:P28 ?_classification.
  ?_country rdfs:label ?_classificationLabel.
  BIND(str(YEAR(?_date)) AS ?year)
  FILTER((LANG(?_classificationLabel)) = "en")
  FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_classificationLabel ?year
HAVING (?count > 1)


USA active by gender by year

prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

#defaultView:LineChart
SELECT ?year (COUNT(?_gender) AS ?count)  (SAMPLE(?_genderLabel) AS ?_genderLabel)  WHERE {
 ?item wdt:P150 wd:Q19.
 ?item wdt:P203 ?_date.
 ?item wdt:P185 ?_gender.
 ?_gender rdfs:label ?_genderLabel.
 BIND(str(YEAR(?_date)) AS ?year)
 FILTER((LANG(?_genderLabel)) = "en")
 FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_genderLabel ?year
HAVING (?count > 1)


Australia active by gender by year

prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

#defaultView:LineChart
SELECT ?year (COUNT(?_gender) AS ?count)  (SAMPLE(?_genderLabel) AS ?_genderLabel)  WHERE {
 ?item wdt:P150 wd:Q132.
 ?item wdt:P203 ?_date.
 ?item wdt:P185 ?_gender.
 ?_gender rdfs:label ?_genderLabel.
 BIND(str(YEAR(?_date)) AS ?year)
 FILTER((LANG(?_genderLabel)) = "en")
 FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_genderLabel ?year
HAVING (?count > 1)

Sportspeople active by sport by year

PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
#defaultView:LineChart
SELECT ?year (COUNT(?_sport) AS ?count)  (SAMPLE(?_sportLabel) AS ?_sportLabel)  WHERE {
 ?item wdt:P150 wd:Q132.
 ?item wdt:P203 ?_date.
 ?item ps:P203/pq:P21 ?_sport.
 ?_sport rdfs:label ?_sportLabel.
 BIND(str(YEAR(?_date)) AS ?year)
 FILTER((LANG(?_sportLabel)) = "en")
 FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_sportLabel ?year
HAVING (?count > 1)


Adapted golfers, sailors and powerchair football players active by sport by year

PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
#defaultView:LineChart
SELECT ?year (COUNT(?_sport) AS ?count)  (SAMPLE(?_sportLabel) AS ?_sportLabel)  WHERE {
     VALUES ?_sport { wd:Q40410 wd:Q86865 wd:Q2430 }
 ?item wdt:P203 ?_date.
 ?item ps:P203/pq:P21 ?_sport.
 ?_sport rdfs:label ?_sportLabel.
 BIND(str(YEAR(?_date)) AS ?year)
 FILTER((LANG(?_sportLabel)) = "en")
 FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_sportLabel ?year
HAVING (?count > 0)

try it

Australians active by year before 1990

This is a list of Australians (P150 completed) who are listed as being active (P203) in or prior to 1990.

prefix p: <http://para-sports.es/wiki/Property:P> 
prefix q: <http://para-sports.es/wiki/Item:Q>

SELECT ?item ?itemLabel ?itemDescription ?_date WHERE {
?item wdt:P150 wd:Q132.
?item wdt:P203 ?_date.
BIND(str(YEAR(?_date)) AS ?year)
FILTER(?_date <= "1990-00-00T00:00:00Z"^^xsd:dateTime )
 
 	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
  }


Number of Nordic skiers by year and country


prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

#defaultView:LineChart
SELECT ?year (COUNT(DISTINCT ?sport)AS ?meep)  (COUNT(?_country) AS ?count)  (SAMPLE(?_countryLabel) AS ?_countryLabel)  WHERE {

  ?sport wdt:P203 ?_date.
  ?sport ps:P203/pq:P21 wd:Q2426.
  ?sport wdt:P150 ?_country.

  ?_country rdfs:label ?_countryLabel.
  BIND(str(YEAR(?_date)) AS ?year)
  FILTER((LANG(?_countryLabel)) = "en")
  FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_countryLabel ?year
HAVING (?count > 0)

try it

Times, weights, distances

In theory, this query should work but there is something wrong with it that it doesn't pull up the right results. It should show the average time for best time per year for all swimmers in a certain event like long course Women's 50 m Freestyle S9. .

PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
#defaultView:LineChart

SELECT 
  ?eventYear
  (avg(?time) as ?averageTime)
  (concat(?courseLabel, " ", ?eventLabel) as ?event)
WHERE {
#BIND (wd:Q7030 as ?item)
?item wdt:P373 ?time;
      ps:P373 ?statement.
?statement pq:P364/rdfs:label ?eventLabel.
FILTER((LANG(?eventLabel)) = "en")
  ?statement pq:P367/rdfs:label ?courseLabel.
FILTER((LANG(?courseLabel)) = "en")
 ?statement pq:P368|pq:P304 ?year.
 BIND(STR(YEAR(?year)) as ?eventYear)
}
GROUP BY ?eventYear ?courseLabel ?eventLabel

National team ranking

Goalball national team ranking

This is a simple list of the all the rankings of national goalball teams by ranking. It is not separated by year, so lots of duplicates.



prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

SELECT ?team ?teamLabel ?rank
WHERE
{
  ?team wdt:P2 wd:Q110;
          wdt:P276 ?rank.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } 
}

Goalball national team ranking

This is a simple list of the average the rankings of national goalball teams by ranking by country, with men and women's national teams by country combined for all combined time periods when they have a ranking.



prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

SELECT ?country ?countryLabel (AVG(?Rank) AS ?avgRank)
WHERE
{
  ?team wdt:P18 ?country;
        wdt:P276 ?Rank.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?country ?countryLabel
HAVING(COUNT(?team) > 0)
ORDER BY DESC(?avgRank)

Win, loss and tie percentages

By specific opponent

Using Special Olympic Madrid's id football team as an example, the query looks at wins, losses and draw percentages against specific opponents.


PREFIX wdt: <http://para-sports.es/prop/direct/>


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

PREFIX statement: <http://para-sports.es/prop/statement/>


# total - 100
# value - x 
# x = value*100/total

SELECT
?opponentLabel

(sum(if(?for > ?against, 1, 0)) as ?win)
(?win*100/count(*) as ?percentWin)

(sum(if(?against > ?for, 1, 0)) as ?loss)
(?loss*100/count(*) as ?percentLoss) 

(sum(if(?for = ?against, 1, 0)) as ?draw)
(?draw*100/count(*) as ?percentDraw)
WHERE {
  wd:Q91817 ps:P512 ?specificoppenent .
  ?specificoppenent statement:P512 ?opponent.
  ?specificoppenent pq:P508 ?for .
  ?specificoppenent pq:P509 ?against .
  BIND( ?for - ?against as ?goaldifference )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

GROUP BY ?opponentLabel

try

All time

Using Special Olympic Madrid's id football team as an example, the query looks at wins, losses and draws based all recorded results.

PREFIX wdt: <http://para-sports.es/prop/direct/>


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

PREFIX statement: <http://para-sports.es/prop/statement/>


# total - 100
# value - x 
# x = value*100/total

SELECT
(sum(if(?for > ?against, 1, 0)) as ?win)
(?win*100/count(*) as ?percentWin)

(sum(if(?against > ?for, 1, 0)) as ?loss)
(?loss*100/count(*) as ?percentLoss) 

(sum(if(?for = ?against, 1, 0)) as ?draw)
(?draw*100/count(*) as ?percentDraw)
WHERE {
  wd:Q91817 ps:P512 ?specificoppenent .
  ?specificoppenent statement:P512 ?opponent.
  ?specificoppenent pq:P508 ?for .
  ?specificoppenent pq:P509 ?against .
  BIND( ?for - ?against as ?goaldifference )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}


try


By competition stage

Using Spain men's national blind football team as an example, the query looks at wins, losses and draws based on specific stages of the competition using P274 - competition stage.

PREFIX wdt: <http://para-sports.es/prop/direct/>


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

PREFIX statement: <http://para-sports.es/prop/statement/>


# total - 100
# value - x 
# x = value*100/total

SELECT
?stageLabel

(sum(if(?for > ?against, 1, 0)) as ?win)
(?win*100/count(*) as ?percentWin)

(sum(if(?against > ?for, 1, 0)) as ?loss)
(?loss*100/count(*) as ?percentLoss) 

(sum(if(?for = ?against, 1, 0)) as ?draw)
(?draw*100/count(*) as ?percentDraw)

WHERE {
  wd:Q19709 ps:P512 ?specificoppenent .
  ?specificoppenent statement:P512 ?opponent.
  ?specificoppenent pq:P274 ?stage .
  ?specificoppenent pq:P508 ?for .
  ?specificoppenent pq:P509 ?against .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

GROUP BY ?stageLabel

try

Country population

This is a simple query that pulls up the population by year of the United States of America. There is only one data point in it, so it is more a demonstration of how to use qualifier statements.



prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>
#Yearly Population stacked by country


SELECT ?year ?population ?objectLabel
WHERE
{
 ?object	wdt:P2 wd:Q20 
 ;	p:P431 ?populationStatement .
 ?populationStatement ps:P431 ?population
 ;	pq:P38 ?date .
 BIND(str(YEAR(?date)) AS ?year)
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } 
} 
ORDER BY ?year ?country


Map

polideportivos in Madrid

This query creates a map of all the polideportivos in Madrid.


prefix p: <http://para-sports.es/wiki/Property:P>
prefix q: <http://para-sports.es/wiki/Item:Q>

#defaultView:Map
SELECT ?place ?placeLabel ?location
WHERE
{
  # Madrid coordinates
  wd:Q19822 wdt:P17 ?MadridLoc .
  SERVICE wikibase:around {
    ?place wdt:P17 ?location .
    bd:serviceParam wikibase:center ?MadridLoc .
    bd:serviceParam wikibase:radius "100" .
  } .
  # Is a polidportivo
  FILTER EXISTS { ?place wdt:P2 wd:Q82377 } .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  } .
}

run


Swimming world records set

Map of where swimming world records were set.

prefix p: <https://para-sports.es/wiki/Property:P>
PREFIX ps: <http://para-sports.es/prop/>
prefix q: <https://para-sports.es/wiki/Item:Q>
prefix pp: <http://para-sports.es/prop/P>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
#defaultView:Map
SELECT ?itemLabel ?coord WHERE {
  ?item wdt:P2 wd:Q91324.
  ?item wdt:P17 ?coord.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

try

Competition query

Number of teams participating in amputee football competitions

This is an example for potential backup of the number of participating teams in a competition to get a count by using P1026, participated in amputee football competition.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>

# backup count of participating amputee football teams by competition
 SELECT  (SAMPLE(?competition) as ?competition) ?competitionLabel  (COUNT(?competition) as ?participatingteams)
WHERE
{
	?subj wdt:P1026 ?competition .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?competitionLabel
ORDER BY DESC(?participatingteams)

try

Madrid query

Districts

Basic information about each district, minus population data as that is variable by year.


prefix p: <https://para-sports.es/wiki/Property:P>
PREFIX ps: <http://para-sports.es/prop/>
prefix q: <https://para-sports.es/wiki/Item:Q>
prefix pp: <http://para-sports.es/prop/P>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>

#Madrid districts
SELECT ?item ?itemLabel  ?perimeter ?barrios ?size  ?deportivos  ?deportivossquaremeters ?deportivossquaremetersdate ?deportivosDM ?deportivossquaremetersdm ?deportivosIM ?deportivossquaremetersim ?basicsportfacilities ?basicsportfacilitiesasof ?basicsportfacilitiesaccesscontrol ?basicsportfacilitiesaccesscontrolarea ?basicsportfacilitiesopenair ?basicsportfacilitiesopenairarea
?footballfields ?tracks ?indoorpools ?outdoorpools 
?popphysicaldisability ?proportionpopphysicaldisability ?popintellectualdisability ?proportionpopintellectualdisability   ?popsensorydisability ?proportionpopsensorydisability
?outpatienthealthcenters ?CentrodeEspecialidades ?CentrodeSalud ?ConsultorioUrbano  ?CentrosSaludMental ?hospitals ?publichospitals ?privatehospitals ?studentsteched
?studentstechedpublic ?studentstechedprivatewithconcentration ?studentstechedprivatewithoutconcentration

WHERE
{
	?item wdt:P2 wd:Q82402 .
	OPTIONAL { ?item wdt:P833 ?perimeter }  #perimeter in meters
	OPTIONAL { ?item wdt:P834 ?barrios }  #number of barrios
	OPTIONAL { ?item wdt:P594 ?size }  #size (square km)
	OPTIONAL { ?item wdt:P836 ?deportivos }  #Centros deportivos Municipales located in administrative area
  	OPTIONAL { ?item wdt:P840 ?deportivossquaremeters }  #area of deportivos (square meters)
	OPTIONAL { ?item wdt:P838 ?deportivosDM }  #total Centros deportivos Municipales with direct management
  	OPTIONAL { ?item ps:P840/pq:P841 ?deportivossquaremetersdm }  #area of deportivos (square meters) under direct management
	OPTIONAL { ?item wdt:P839 ?deportivosIM }  #total Centros deportivos Municipales with indirect management
  	OPTIONAL { ?item ps:P840/pq:P842 ?deportivossquaremetersim }  # area of deportivos (square meters) under indirect management
  	OPTIONAL { ?item ps:P840/pq:P247 ?deportivossquaremetersdate }  #as of square meters
	OPTIONAL { ?item wdt:P843 ?basicsportfacilities }  #total basic sports facilities
    OPTIONAL { ?item ps:P843/pq:P247 ?basicsportfacilitiesasof } #total basic sports facilities as of
    OPTIONAL { ?item ps:P843/pq:P844 ?basicsportfacilitiesaccesscontrol } #total basic sports facilities with access control
    OPTIONAL { ?item ps:P843/pq:P847 ?basicsportfacilitiesopenairarea } #total area (square meters) for basic open air sports facilities
    OPTIONAL { ?item ps:P843/pq:P846 ?basicsportfacilitiesopenair } #total basic open air sports facilities
    OPTIONAL { ?item ps:P843/pq:P845 ?basicsportfacilitiesaccesscontrolarea } #total area (square meters) for sports facilities with access control
    OPTIONAL { ?item wdt:P848 ?footballfields }  #total football fields
	OPTIONAL { ?item wdt:P849 ?tracks }  #total track and field facilities
	OPTIONAL { ?item wdt:P850 ?indoorpools }  #total indoor swimming pools
	OPTIONAL { ?item wdt:P851 ?outdoorpools }  #total outdoor swimming pools
	OPTIONAL { ?item wdt:P864 ?popphysicaldisability }  #total population with recognized disability physical in 2014
  	OPTIONAL { ?item wdt:P873 ?proportionpopphysicaldisability }  #Proportion of people with recognized physical disabilities for every 1,000 inhabitants in 2014
	OPTIONAL { ?item wdt:P867 ?popintellectualdisability }  #total population with recognized intellectual disability in 2014
	OPTIONAL { ?item wdt:P870 ?popsensorydisability }  #total population with recognized sensory disability in 2014
	OPTIONAL { ?item wdt:P876 ?proportionpopintellectualdisability } # Proportion of people with recognized intellectual disabilities for every 1,000 inhabitants
	OPTIONAL { ?item wdt:P879 ?proportionpopsensorydisability }  # Proportion of people with recognized sensory disabilities for every 1,000 inhabitants
	OPTIONAL { ?item wdt:P898 ?outpatienthealthcenters }  # total outpatient health centers located in administrative area
	OPTIONAL { ?item wdt:P899 ?CentrodeEspecialidades }  #total Centro de Especialidades located in administrative area
	OPTIONAL { ?item wdt:P900 ?CentrodeSalud }  #total Centro de Salud located in administrative area
	OPTIONAL { ?item wdt:P901 ?ConsultorioUrbano }  #total Consultorio Urbano located in administrative area
	OPTIONAL { ?item wdt:P902 ?CentrosSaludMental }  #total Centros Salud Mental located in administrative area
	OPTIONAL { ?item wdt:P903 ?hospitals }  #total hospitals located in administrative area
	OPTIONAL { ?item wdt:P904 ?publichospitals }  #total public hospitals located in administrative area
	OPTIONAL { ?item wdt:P905 ?privatehospitals }  #total private hospitals located in administrative area
	OPTIONAL { ?item wdt:P913 ?studentsteched }  #total special education students in technical education program in 2016
	OPTIONAL { ?item wdt:P914 ?studentstechedpublic }  #total special education students in technical education program (public school)
	OPTIONAL { ?item wdt:P915 ?studentstechedprivatewithconcentration }  #total special education students in technical education program (private school with concentration)
	OPTIONAL { ?item wdt:P915 ?studentstechedprivatewithoutconcentration }  #total special education students in technical education program (private school without concentration)
	
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}
}

try

Count of polideportivos by district with pool hoists

This statement useful as it also uses identifer statements.


prefix p: <http://para-sports.es/prop/>
PREFIX ps: <http://para-sports.es/prop/statement/>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>
#defaultView:BarChart
SELECT ?location ?locationLabel (count(DISTINCT ?item) as ?number) ?disability ?disabilityLabel  {
  ?item wdt:P2 wd:Q82377 .
   ?item p:P825 ?s .
          ?s ps:P825 ?z .
          ?s pq:P826 ?disability .
  ?item wdt:P18 ?location .
  ?location wdt:P2 wd:Q82402 .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?location ?locationLabel ?disability ?disabilityLabel 
ORDER BY ?locationLabel

try

Public toilets

public toilet count by district

Total disability population

try it

Disability sport disability offerings for polideportivo by district

 prefix p: <http://para-sports.es/prop/>
PREFIX ps: <http://para-sports.es/prop/statement/>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>
#defaultView:BarChart
SELECT ?location ?locationLabel (count(DISTINCT ?item) as ?number) ?disability ?disabilityLabel  {
  ?item wdt:P2 wd:Q82377 .
  ?item wdt:P26 ?disability .
  ?item wdt:P18 ?location .
  ?location wdt:P2 wd:Q82402 .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?location ?locationLabel ?disability ?disabilityLabel 
ORDER BY ?locationLabel 

try it

Disability services by health facilities by district

try

Total disability population

try


Total disability population by year

try it

Location of Renfe stations with elevators

try

Location of metro stations with elevators

try

Total funding by metro station and district to fund metro improvements

try

other

Number of times sources used on an item

This query counts the number of times a reference from P143 appears on an item page.



prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pe: <http://para-sports.es/entity/>

SELECT ?subject ?subsubobject ?subsubobjectLabel (COUNT(?subsubobject) as ?count)
WHERE {
  # BIND (pe:Q17483 as ?subject)
  ?subject ?predicate [prov:wasDerivedFrom/pr:P143 ?subsubobject].
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?subject ?subsubobject ?subsubobjectLabel
ORDER BY ?subject
LIMIT 100

try it


Number of unique sources used on an item

This query counts the number of unique times a reference from P143 appears on an item page.

prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>
PREFIX ps: <http://para-sports.es/prop/>
PREFIX pq: <http://para-sports.es/prop/qualifier/>
PREFIX pr: <http://para-sports.es/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pe: <http://para-sports.es/entity/>

SELECT ?subject (COUNT(DISTINCT ?subsubobject) as ?count)
WHERE {
  # BIND (pe:Q17483 as ?subject)
  ?subject ?predicate [prov:wasDerivedFrom/pr:P143 ?subsubobject].
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?subject
ORDER BY DESC(?count)
LIMIT 100

try it

Queries for items to be located that need items bulk changed

Mislabeled men

This example provides a list of people who have Item:Q58593 linked to instead of Item:Q2987.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Mislinked male item
SELECT ?item ?itemLabel ?itemDescription ?dob
WHERE
{
	?item wdt:P185 wd:Q58593 .
	OPTIONAL { ?item wdt:P130 ?dob }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

Mislabeled instance of

This example provides a list of disability types who have Item:Q67067 linked to instead of Item:Q47998.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Mislinked male item
SELECT ?item ?itemLabel ?itemDescription
WHERE
{
	?item wdt:P2 wd:Q67067 .
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}


Mislabeled wheelchair basketball

This example provides a list of sports who have Item:Q22371 linked to instead of Item:Q85.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Mislinked wheelchair basketball item
SELECT ?item ?itemLabel ?itemDescription
WHERE
{
	?item wdt:P2 wd:Q22371 .
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}


Mislabeled Hamish

This example provides a list of flag bearers who have Item:Q63198 linked to instead of Item:Q8180.


prefix p: <https://para-sports.es/wiki/Property:P>
prefix q: <https://para-sports.es/wiki/Item:Q>

#Mislinked wheelchair basketball item
SELECT ?item ?itemLabel ?itemDescription
WHERE
{
	?item wdt:P604 wd:Q63198 .
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}