MAX
The MAX function returns the maximum value from the specified set of values.
MAX Syntax
Use the following syntax when incorporating the MAX function in queries:
MAX(expression)
Where expression evaluates to any data type except for boolean.
Note: A GROUP BY statement is required for queries that contain MAX functions if the results clause lists non-aggregate variables. Include all non-aggregated variables in the GROUP BY statement.
MAX 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 to list the top 10 events with the highest number of tickets sold in one transaction:
SELECT ?event (MAX(?tickets) AS ?max_tickets) FROM <tickit> WHERE { ?listing <numtickets> ?tickets . ?listing <eventid> ?id . ?id <eventname> ?event . } GROUP BY ?event ORDER BY desc(?max_tickets) LIMIT 10
event | max_tickets -------------------------------+------------- Eugene Onegin | 30 A Bronx Tale | 30 Kenny Wayne Shepherd | 30 Duffy | 30 Huey Lewis and the News | 30 Ring Cycle | 30 Girl Talk | 30 Robert Plant and Alison Krauss | 30 Sweet Honey in the Rock | 30 Kansas | 30 10 rows