簡體   English   中英

SPARQL組由子字符串和平均值組成

[英]SPARQL group by a substring and average

我正在查詢一個大型數據集(每小時記錄一次近20年的溫度),我寧願得到一個總結,例如每日溫度。

這里有一個示例查詢: http//www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid = hu5rbc7W

PREFIX opensheff: <uri://opensheffield.org/properties#>

select ?time ?temp where {
    ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/Weather_Mast/Weather_Mast.ic> ;
       opensheff:rawValue ?temp ;
       <http://purl.oclc.org/NET/ssnx/ssn#endTime> ?time .
  FILTER (str(?time) > "2011-09-24")
}
ORDER BY ASC(?time)

結果如下:

time                temp
"2011-09-24T00:00Z" 12.31
"2011-09-24T01:00Z" 11.68
"2011-09-24T02:00Z" 11.92
"2011-09-24T03:00Z" 11.59

現在我想按日期字符串的一部分進行分組,以獲得每日平均溫度:

time            temp
"2011-09-24"    12.3  # or whatever
"2011-09-23"    11.7
"2011-09-22"    11.9
"2011-09-21"    11.6

那么,我如何按時間分組?

最終解決了它。 在這里跑:

http://www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid=j8m0Qk6s

代碼:PREFIX opensheff:

select ?d AVG(?temp) as ?day_temp
where {
    ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/Weather_Mast/Weather_Mast.ic> ;
       opensheff:rawValue ?temp ;
       <http://purl.oclc.org/NET/ssnx/ssn#endTime> ?time .
    BIND( SUBSTR(?time, 1, 10) AS ?d ) .
}
GROUP BY ?d
ORDER BY ASC(?d)

我們使用BIND將新變量設置為所需的子字符串,然后通過該變量進行分組和平均就足夠了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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