SPARQL结果格式将行连接并转换为列

时间:2015-07-28 21:20:37

标签: sparql

嗨,我有这个架构

<product> dprop:title "title"en; dprop:description "description:en.

提供架构是

<offer> dprop:condition 1; dprop:proce 123. # condition 1 is for new offer and 0 is used offer

产品和报价之间的关系是

<offer> oprop:isOfferOf <product>

所以现在我有产品ID列表,我希望单行反对这些产品

0:- Product Id
1:- Minim price in new offers
2:- Minim price in used offers
3:- Id of that offer which have  minim price with condition used
4:- Id of that offer which have  minim price with condition new
5:- Id of that offer which have  minim price with condition used
6:- Total counts for New offers against each product
7:- Total counts for Used offers against each product

这是我的查询

SELECT ?minPrice  ?cond  ?newOffs  ?usedOffs  ?pid  ?newOid  ?usedOid
    WHERE {
      {
        SELECT ?pid ?cond ( sample(?offid) AS ?oid )
          ( MIN(?price) AS ?minPrice )
          (sum(?newIncrement) AS ?newOffs)
          (sum(?oldIncrement) AS ?usedOffs)
        WHERE{
          ?pid ^mod:isOfferOf ?offid. ?offid dprop:condition ?cond; dprop:price ?price.
          BIND (if( ?cond = 1, 0, 1) AS ?newIncrement).
          BIND (if( ?cond = 1, 1, 0) AS ?oldIncrement).
          VALUES ?pid { prod:Rl5RVl5R  prod:Rl5RVl5Q prod:Rl5RVl5W prod:Rl5RVl5Y prod:Rl5RVl5U }
        } GROUP BY ?pid ?cond
      }
      BIND(IF(?cond = 0, ?oid , ?null) AS ?usedOid).
      BIND(IF(?cond = 1, ?oid , ?null) AS ?newOid).
    }

现在在我的查询中我有productID condition(new/1) offerId(new) and minPrice(from new offers only )相同的重复行,但是使用过的商品数据(id,minPrice,count)我希望将两行合并为group by ?pid 以下是我的查询的live Query和结果Preview

0 个答案:

没有答案