繁体   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