簡體   English   中英

在SPARQL中過濾預計表達式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM