How can I from SQL Queries when using Aggregate functions like count, min, max etc?

How can I from SQL Queries when using Aggregate functions like count, min, max etc?

How to Form SQL Queries When Using Aggregate Functions (COUNT, MIN, MAX, SUM, AVG)

Points to remember before adding a Query Monitor:

Notes
  • The query must be entered as a single line without Line breaks.
  • A maximum of 5 queries can be configured in a single Database Query Monitor.
  • Multiple queries should be separated using a new line delimiter.
  • The monitor displays a maximum of 50 rows in the output. This limit can be changed under Settings of Applications Manager -> Performance Polling -> Optimize Data Collection -> Choose Monitor Type as Script / Database Query Monitor -> "Query monitor row count" text box. Increasing the limit to higher number will increase load to Applications Manager monitoring behavior.
  • If the query returns multiple columns, we recommend selecting an unique ID columns or non-volatile string column as the Primary Key. If no suitable string column exists, add a dummy identifier as shown below.


Why do I get the "without an identifier" error upon adding a Query Monitor?


Applications Manager requires every Database Query Monitor to have an Identifier (Primary Key) that uniquely identifies each result row.

If your query returns only aggregate values (such as COUNT, SUM, MIN, MAX, or AVG), there is no identifier available, resulting in the "without an identifier" error.

When is a dummy identifier required?

A dummy identifier is required only if your query does not already return a unique column.

Query ResultAction
Only aggregate function(s)Add a dummy identifier.
Returns a unique column (Primary Key, ID, Session ID, etc.)Use that column as the Primary Key. No dummy identifier is required.
Returns a non-unique column (Status, Category, Type, etc.)Add a dummy identifier or use a unique column instead.


How to add a dummy identifier?

Oracle / MySQL / Sybase:

SELECT 'Number of Pending Tasks', COUNT(*) AS TotalCount FROM app_pending_tasks

Use 'Number of Pending Tasks' as the Primary Key.

SQL Server / PostgreSQL / Db2 / Kingbase:
SELECT 'Number of Pending Tasks' AS TaskName, COUNT(*) AS TotalCount FROM app_pending_tasks

Use TaskName as the Primary Key.

Example

❌ Incorrect

SELECT COUNT(*) FROM app_pending_tasks

✅ Correct

SELECT 'Number of Pending Tasks' AS TaskName, COUNT(*) AS TotalCount FROM app_pending_tasks


Before Saving the Query

Verify that:

  • Your query returns either:
    • a unique column (such as an ID or Primary Key), or
    • a dummy identifier (string literal).
  • The identifier is configured as the Primary Key in the Database Query Monitor's output table.
  • If your query uses GROUP BY, ensure the identifier column is included in the GROUP BY clause.

Still seeing the error?

If the issue persists after following the above guidelines, contact Applications Manager Support with:

  • The complete SQL query.
  • Add Monitor/Edit Monitor/Monitor Page screenshot.
  • The database type (Oracle, SQL Server, PostgreSQL, MySQL, etc.).
  • The Applications Manager build number.

                    New to ADSelfService Plus?

                      • Related Articles

                      • Database Query Monitor FAQ

                        How to fix an "Unable to find the Primary Key for tablename" error displayed after adding a query monitor? After adding a Database Query Monitor, users must select and update a Primary Key for each table. The primary key can be a single column or a ...
                      • Applications Manager Database Migration Using SQL Dump

                        Step 1: Rename Directories Skip this step if the directories are already renamed. Rename <AppManager_home>/working/pgsql to <AppManager_home>/working/pgsql_11. Rename <AppManager_home>/working/pgsql_15.5 to <AppManager_home>/working/pgsql. Step 1.1: ...
                      • Integrating Applications Manager backend Microsoft SQL database with Power BI Desktop

                        Overview This KB provides step-by-step instructions to connect Power BI Desktop to your Applications Manager's Microsoft SQL backend database, enabling you to create custom reports and dashboards using Applications Manager's performance metrics and ...
                      • APM Insight provides information on the parameters it sends to the SQL queries

                        The parameters in slow SQL queries can be tracked and displayed under the traces tab. We have the option to obfuscate the values of SQL query parameters using a configuration "Obfuscate SQL Parameters". It will be enabled by default. The screenshot ...
                      • Azure SQL Database - FAQ

                        1. Why have we removed the Diagnostic Settings dependency in Azure SQL Database monitor? Till APM v15240: Azure SQL Database was using Diagnostic Settings to perform data collection. Prerequisites had to be fulfilled to turn on Diagnostic Settings ...