# SPARQL 語法教學 作者: 朱庭宏 ## SELECT (查詢) ```sql= SELECT ?item ?itemLabel WHERE { } # ?後塞欄位名稱 若要顯示其標籤需加Label ```  ## AS (代名) ```sql= SELECT ?item ?itemLabel (?itemLabel AS ?標籤) WHERE { } # AS後面仍需加變數 ```  ### 注意: 若是直接寫這樣他屬性的欄位會是空值 ```sql= SELECT ?item (?itemLabel AS ?標籤) WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh".} ?item wdt:P31 wd:Q207694. } ```  應修該為下: ```sql= SELECT ?item (?itemLabel AS ?標籤) WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh". ?item rdfs:label ?itemLabel. } ?item wdt:P31 wd:Q207694. } ```  ## WHERE (條件) 在```SERVICE wikibase:label```中```bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh".```子句再設定Label的語言,```?item rdfs:label ?itemLabel.```子句則是將```?itemLabel```變數參照到```?item```變數的標籤值 ```?item wdt:P31 wd:Q207694.```子句將```P31=Q207694```指定給```?item```變數 ## ORDER (排序) ```sql= SELECT ?item (?itemLabel AS ?標籤) WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh". ?item rdfs:label ?itemLabel. } ?item wdt:P31 wd:Q207694. } ORDER BY ASC(?item) # ASC為遞增,DESC為遞減 ```  ## LIMIT (比數限制) ```sql= SELECT ?item (?itemLabel AS ?標籤) WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh". ?item rdfs:label ?itemLabel. } ?item wdt:P31 wd:Q207694. } ORDER BY ASC(?標籤) LIMIT 100 # 僅顯示100筆紀錄 ```  ## DISTINCT (去除重複) ```sql= SELECT DISTINCT ?item (?itemLabel AS ?標籤) WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],zh". ?item rdfs:label ?itemLabel. } ?item wdt:P31 wd:Q207694. } ORDER BY ASC(?標籤) LIMIT 100 ``` ## 查詢出生年月日 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up