title: MAX in SPARQL 1.1?
body: <p>I am a beginner at SPARQL 1.1. I have an N-Triples file like below. I want to find the maximum value for <code>Work_RVU</code> (the last attribute) and the related code (the 4th attribute).</p>
  
  <pre><code>&lt;file://PPRVU12.xlsx/69540&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns?#type&gt; &lt;http://cms.gov/HCPCS&gt; .
  &lt;file://PPRVU12.xlsx/69540&gt; &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; "Remove ear lesion" .
  &lt;file://PPRVU12.xlsx/69540&gt; &lt;file://PPRVU12.xlsx#Status_Code&gt; "A" .
  &lt;file://PPRVU12.xlsx/69540&gt; &lt;file://PPRVU12.xlsx#Code&gt; "69540" .
  &lt;file://PPRVU12.xlsx/69540&gt; &lt;file://PPRVU12.xlsx#Work_RVU&gt; "1.25" .
  
  &lt;file://PPRVU12.xlsx/69550&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns?#type&gt; &lt;http://cms.gov/HCPCS&gt; .
  &lt;file://PPRVU12.xlsx/69550&gt; &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; "Remove ear lesion" .
  &lt;file://PPRVU12.xlsx/69550&gt; &lt;file://PPRVU12.xlsx#Status_Code&gt; "A" .
  &lt;file://PPRVU12.xlsx/69550&gt; &lt;file://PPRVU12.xlsx#Code&gt; "69550" .
  &lt;file://PPRVU12.xlsx/69550&gt; &lt;file://PPRVU12.xlsx#Work_RVU&gt; "11.15" .
  
  &lt;file://PPRVU12.xlsx/69552&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns?#type&gt; &lt;http://cms.gov/HCPCS&gt; .
  &lt;file://PPRVU12.xlsx/69552&gt; &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; "Remove ear lesion" .
  &lt;file://PPRVU12.xlsx/69552&gt; &lt;file://PPRVU12.xlsx#Status_Code&gt; "A" .
  &lt;file://PPRVU12.xlsx/69552&gt; &lt;file://PPRVU12.xlsx#Code&gt; "69552" .
  &lt;file://PPRVU12.xlsx/69552&gt; &lt;file://PPRVU12.xlsx#Work_RVU&gt; "19.81" .
  </code></pre>
  
  <p>The maximum RVU should be 19.81 and the code should be “69552”. I could print 19.81 but always print “69540”, which means it always selects the first code it meets each time.</p>
  
  <p>My SPARQL code is below:</p>
  
  <pre><code>PREFIX pre: &lt;file://PPRVU12.xlsx#&gt;
  SELECT ?code (MAX (?val) AS ?Max_RVU)
  WHERE{
      ?code pre:Work_RVU ?val .
  }
  </code></pre>
  
  <p>Is there a mistake in this query? I also tried another query,</p>
  
  <pre><code>PREFIX pre: &lt;file://PPRVU12.xlsx#&gt;
  PREFIX head: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns?#&gt;
  SELECT ?code (MAX (?val) AS ?Max_RVU)
  WHERE{
      ?d head:type &lt;http://cms.gov/HCPCS&gt; .
      ?d pre:Code ?code .
      ?d pre:Work_RVU ?val .
  }
  </code></pre>
  
  <p>but the result was the same. </p>