[英]Filter projected expressions in SPARQL
這是一個示例查詢:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
SELECT ?title (?p AS ?fullPrice) (?fullPrice*(1-?discount) AS ?customerPrice)
WHERE {
?x ns:price ?p .
?x dc:title ?title .
?x ns:discount ?discount
}
結果將是:
| title | fullPrice | customerPrice |
| "The Semantic Web" | 23 | 17.25 |
| "SPARQL Tutorial" | 42 | 33.6 |
我只想顯示customerPrice> 20。
我在查詢結束時嘗試了HAVING (?customerPrice > 20)
,但似乎沒有看到投影表達式。
還有其他辦法嗎?
將計算變量從SELECT
列表移動到查詢模式內的BIND
子句中。 然后你可以在變量上使用FILTER
:
SELECT ?title ?fullPrice ?customerPrice
WHERE {
?x ns:price ?fullPrice.
?x dc:title ?title.
?x ns:discount ?discount
BIND (?fullPrice * (1-?discount) AS ?customerPrice)
FILTER (?customerPrice > 20)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.