title: IF statement in SPARQL
body: <p>I have the following SPARQL query:</p>
  
  <pre><code>PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;
  SELECT distinct  count (?Montreal) as ?Montreal count(?Toronto) as ?Toronto
  WHERE
  {
  {?Montreal rdf:type yago:HospitalsInMontreal} UNION {?Toronto rdf:type yago:HospitalsInToronto}.
  }
  </code></pre>
  
  <p>This query results in:</p>
  
  <p>Montreal = 20
  Toronto = 28</p>
  
  <p>What I want is:
  I want to edit the query and instead of giving 20 and 28, I want to compare the results such that 
  If number of hospitals in Montreal is larger than the number of hospitals in Toronto then:</p>
  
  <p>Montreal = 1
  Toronto = 2</p>
  
  <p>If the number of hospitals in Toronto is larger than the number of hospitals in Montreal then:</p>
  
  <p>Montreal = 2<br>
  Toronto = 1</p>
  
  <p>I tried this query but it didn't work:</p>
  
  <pre><code>PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;
  SELECT distinct  count (?Montreal) as ?Montreal count(?Toronto) as ?Toronto
  WHERE
  {
  {?Montreal rdf:type yago:HospitalsInMontreal} UNION {?Toronto rdf:type yago:HospitalsInToronto}.
  LET( ?Montreal := IF( ?Montreal &gt; ?Toronto, -1, 1 ).
  }
  </code></pre>
  
  <p>Thanks</p>