CASE Clause
Use the CASE clause within the SELECT clause to add conditions to your ADQL query. It helps you to transform data with the specified condition. This clause supports aggregation and bucketing functions.
Syntax
SELECT CASE WHEN (condition) THEN (action 1) ELSE (action 2) END FROM event_type
SELECT CASE WHEN (condition 1) THEN (action 1)
WHEN (condition 2) THEN (action 2)
WHEN (condition 3) THEN (action 3)
ELSE (action 4) END FROM event_type
Examples using Metric Functions
You can use metric functionsin the CASE clause for aggregations. The following are some examples with count and average aggregation functions:
Count the Transactions based on User Experience in Applications
SELECT application, CASE WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount ELSE count(userExperience) AS otherTransactionsCount END FROM transactions
Application
normalTransactionsCount
otherTransactionsCount
View the User Experience Values and the Total Transactions Count in Applications
SELECT application, CASE WHEN userExperience = "NORMAL" THEN userExperience AS userExperienceValues ELSE userExperience AS otherUserExperienceValues END, count(userExperience) AS totalTransactionsCount FROM transactions
null
. View the Application's Normal and Other Transactions Count
SELECT application, transactionName, CASE WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount ELSE count(userExperience) AS otherTransactionsCount END FROM transactions
Application
Transaction Name
normalTransactionsCount
otherTransactionsCount
View the Count for each User Experience Values
SELECT count(*), userExperience, CASE WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount ELSE count(userExperience) AS otherTransactionsCount END FROM transactions
View the Transaction Counts for Applications having High Response Time
SELECT responseTime, CASE WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount ELSE count(userExperience) AS otherTransactionsCount END FROM transactions WHERE responseTime > 10
Response Time
normalTransactionsCount
otherTransactionsCount
Calculate Average Response Time for the User Experience Transactions
SELECT application, CASE WHEN userExperience="NORMAL" THEN avg(responseTime) AS normalTransactionsAvgResponseTime WHEN userExperience="SLOW" THEN avg(responseTime) AS slowTransactionsAvgResponseTime ELSE avg(responseTime) AS otherTransactionsAvgResponseTime END FROM transactions
Application
normalTransactionsAvgResponseTime
slowTransactionsAvgResponseTime
otherTransactionsAvgResponseTime
Examples using without Metric Functions
The following are some examples without metric functions:
View User Experience Values with their Response Times
SELECT CASE WHEN userExperience = "NORMAL" THEN userExperience AS userExperienceValues ELSE userExperience AS otherUserExperienceValues END, responseTime FROM transactions
null
. userExperienceValues
otherUserExperienceValues
Response Time
View User Experience Values that are not NULL with their Response Times
SELECT CASE WHEN userExperience = "NORMAL" THEN userExperience AS userExperienceValues ELSE userExperience AS otherUserExperienceValues END, responseTime FROM transactions WHERE userExperience IS NOT NULL
null
. userExperienceValues
otherUserExperienceValues
Response Time
Statements after the CASE Clause
The CASE clause applies conditional logic to compute specific metrics and cannot nest separate metrics defined outside the clause. Below are valid ADQL queries, with results displayed in the specified order:
SELECT application,
CASE
WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount
ELSE count(userExperience) AS otherTransactionsCount
END,
count(*)
FROM transactions
- Application
- normalTransactionCount
- otherTransactionCount
- count
SELECT application,
count(*),
CASE
WHEN userExperience = "NORMAL" THEN count(userExperience) AS normalTransactionsCount
ELSE count(userExperience) AS otherTransactionsCount
END
FROM transactions
- Application
- count
- normalTransactionCount
- otherTransactionCount
- The CASE block is used for conditional logic to compute specific metrics like
normalTransactionsCount
orotherTransactionsCount
. - The
count(*)
is a separate metric that reflects the total count of all transactions grouped by application.
Limitations
The MAUI Agent has the following limitations for which crash data is reported:
- Reported: Managed crashes - crashes that occur on .NET Runtime).
- Not reported: Native crashes - crashes that occur on Objective-C runtime.