<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/isparql/xslt/dynamic-page.xsl"?><iSPARQL xmlns="urn:schemas-openlink-com:isparql"><ISparqlDynamicPage><proxy>true</proxy><query><![CDATA[#service:/sparql
#should-sponge:soft

define sql:signal-void-variables 1
prefix tpch: <http://www.openlinksw.com/schemas/tpch#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select
  (bif:LEFT (?cust+>tpch:phone, 2)) as ?cntrycode,
  (count (1)) as ?numcust,
  sum (?cust+>tpch:acctbal) as ?totacctbal
from <http://demo.openlinksw.com/tpch>
where {
      { select
          (avg (?cust2+>tpch:acctbal)) as ?acctbal_threshold
        where
          {
            ?cust2 a tpch:customer .
            filter ((?cust2+>tpch:acctbal > 0.00) &&
              bif:LEFT (?cust2+>tpch:phone, 2) in ("13", "35", "31", "23", "29", "30", "17", "18") )
          }
      }
    ?cust a tpch:customer .
    optional { select ?cust (count(?ord)) as ?ord_cnt
      where { ?cust a tpch:customer ; tpch:customer_of ?ord } }
    filter ((?cust+>tpch:acctbal > ?acctbal_threshold) &&
      bif:LEFT (?cust+>tpch:phone, 2) in ("13", "35", "31", "23", "29", "30", "17", "18") &&
      !bound (?ord_cnt) )
  }
order by
  (bif:LEFT (?cust+>tpch:phone, 2))
]]></query><graph>http://demo.openlinksw.com/tpch</graph></ISparqlDynamicPage><should_sponge>soft</should_sponge><service>/sparql</service></iSPARQL>