Arithmetic Operator Examples
This topic provides examples for using the following arithmetic operators in queries:
- + for addition
- - for subtraction
- * for multiplication
- / for division
The example queries below run against the AnzoGraph sample Tickit data set, which captures sales activity for a fictional Tickit website where people buy and sell tickets for sporting events, shows, and concerts. You can load and explore this data set. For more information, see Working with the Tickit Data.
The following example queries the sample Tickit data and uses the subtraction operator ( - ) to determine the amount left from each ticket sale after the commission is subtracted from the total price paid.
SELECT ?sale (?price - ?comm AS ?minus_commission) FROM <tickit> WHERE { ?sale <pricepaid> ?price . ?sale <commission> ?comm . } ORDER BY ?sale LIMIT 100
sale | minus_commission ------------+------------------ sales1 | 618.800000 sales10 | 55.250000 sales100 | 137.700000 sales1000 | 160.650000 sales10000 | 158.950000 sales100000 | 412.250000 sales100001 | 256.700000 sales100002 | 221.000000 sales100003 | 314.500000 sales100004 | 229.500000 ... 100 rows
This example query uses multiplication operators (*) to calculate the total sales multiplied by 5%:
SELECT (((?totalsales * .05)*100) AS ?projection) FROM <tickit> WHERE { { SELECT (sum(?pricepaid) AS ?totalsales) WHERE { ?s <pricepaid> ?pricepaid . } } }
projection ------------------ 553827155.000000 1 rows