COUNT
The COUNT function counts the number of times the specified value is bound to the given variable.
COUNT Syntax
Use the following syntax when incorporating the COUNT function in queries:
COUNT( [ DISTINCT ] expression)
Where expression evaluates to any data type. Include DISTINCT to limit the results to the unique values for the expression.
Note: A GROUP BY statement is required for queries that contain COUNT functions if the results clause lists non-aggregate variables. Include all non-aggregated variables in the GROUP BY statement.
COUNT Examples
The example queries in this section 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 set to count the number of people who have the same last name:
SELECT (COUNT(?person) AS ?count) ?lastname FROM <tickit> WHERE { ?person <lastname> ?lastname . } GROUP BY ?lastname ORDER BY ?lastname LIMIT 10
count | lastname ------+----------- 49 | Abbott 57 | Acevedo 52 | Acosta 63 | Adams 58 | Adkins 54 | Aguilar 40 | Aguirre 45 | Albert 41 | Alexander 45 | Alford 10 rows