Search code examples
excelformatoutputsparql

Displaying SPARQL Output in Column rather than Row


I have several SPARQL queries like the following:

SELECT ?mept ?uspt ?sapt ?rept ?sspt 
WHERE {{SELECT (COUNT(?mep) AS ?mept)
    WHERE {codo:MiddleEastCluster codo:hasMember ?mep.}}
    {SELECT (COUNT(?usp) AS ?uspt)
    WHERE {codo:USACluster codo:hasMember ?usp.}}
    {SELECT (COUNT(?sap) AS ?sapt)
    WHERE {codo:SouthAmericaCluster codo:hasMember ?sap.}}
    {SELECT (COUNT(?rep) AS ?rept)
    WHERE {codo:RestOfEuropeCluster codo:hasMember ?rep.}}
    {SELECT (COUNT(?ssp) AS ?sspt)
    WHERE {codo:SouthernStatesCluster codo:hasMember ?ssp.}}}

The actual query is much larger, I shortened it for this example. I take this information and then put it into Excel to create bar and pie charts illustrating our data. As this (and other queries) currently work they display the results in a row like this:

?mept  ?uspt  ?sapt  ?rept  ?sspt

 515    7       5     22      481

I would prefer that it was formatted as a column like this:

?mept 515
?uspt 7
?sapt 5
?rept 22
?sspt 481

That would make it easier to copy and paste the data directly into Excel. Is there a simple way to do this with SPARQL? I've found examples online that do much more complicated things like directly output the data from SPARQL to Excel. I don't need anything that sophisticated, just an easy way to format the output as a column rather than a row.


Solution

  • As suggested in comments, revised query --

    SELECT                        ?type
           ( COUNT ( ?member ) AS ?cnt) 
    WHERE 
      { VALUES  ( ?cluster               ?type ) 
          {     ( codo:MiddleEastCluster "mep" )
                ( codo:USACluster        "usp" )
          }     
        ?cluster  codo:hasMember  ?member 
      } 
    GROUP BY ?cluster ?type