The following query is being used to create a pie within a business intelligence dashboard. The query runs and returns the correct data, however it is extremely slow (about 36 seconds). Can anyone see a way to optimize this query?
SELECT
Name,
Date,
Severity,
PMissing
FROM
(
SELECT
Name,
Date,
Severity,
PMissing,
DENSE_RANK() OVER (PARTITION BY Name ORDER BY ate DESC) AS Rnk
FROM PctbyP
WHERE (Name like '%front-%'
OR Name like '%back-%'
OR Name like '%ap-%'
OR Name like '%mps-%'
OR Name like '%mg-%')
)t
WHERE rnk=1
AND PMissing != '0'
Create an indexed view:
, then create an index on the table:
, then use this query: