In the display-field editor, the (Count) field is listed as the first display field. If you include the (Count) field when you design a query, the generated query includes a Count (dbid) aggregate. See the CountBy State-Severity-Priority.qry included with the report samples for an example.