sparql - 在 SPARQL 中过滤投影表达式

标签 sparql rdf triplestore

这是一个示例查询:

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)
}

关于sparql - 在 SPARQL 中过滤投影表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55627922/

相关文章:

rdf - 将 freebase MQL 转换为 SPARQL

java - 使用 JENA 的参数化 SPARQL 查询

data-structures - 持久表达有向图的最标准文件格式和表示法是什么?

azure - 如何在Cosmos DB中基于三元组列表构建图?

sparql - 三重存储中的开放世界假设和 SPARQL

rdf - 用于教育目的的最简单的 SPARQL 实现?

drupal - 将 SPARQL 查询转化为可视化

database - 如何将表格转换为rdf图?

path - 具有任意属性的SPARQL属性路径查询

python - 来自 AllegroGraph Python API 的 Prolog 查询中的 OWL 推理