Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:08:31+00:00 2026-06-17T10:08:31+00:00

The following query is being used to create a pie within a business intelligence

  • 0

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'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:08:32+00:00Added an answer on June 17, 2026 at 10:08 am

    Create an indexed view:

    CREATE VIEW
            V_PctbyP_Name
    WITH SCHEMABINDING
    AS
    SELECT  Name, COUNT_BIG(*) AS Cnt
    FROM    dbo.PctbyP
    GROUP BY
            Name
    
    CREATE UNIQUE CLUSTERED INDEX
            UX_V_PctbyP_Name
    ON      V_PctbyP_Name (Name)
    

    , then create an index on the table:

    CREATE INDEX
            IX_PctbyP_Name_Date
    ON      PctbyP (Name, [Date])
    

    , then use this query:

    SELECT  pa.*
    FROM    V_PctbyP_Name vp
    CROSS APPLY
            (
            SELECT  TOP 1 WITH TIES
                    Name, [Date], Severity, PMissing
            FROM    PctbyP p
            WHERE   p.Name = vp.Name
            ORDER BY
                    [Date] DESC
            ) pa
    WHERE   (
            vp.Name LIKE '%front-%'
            OR
            vp.Name LIKE '%back-%'
            OR
            vp.Name LIKE '%ap-%'
            OR
            vp.Name LIKE '%mps-%'
            OR
            vp.Name LIKE '%mg-%'
            )
            AND pa.PMissing <> '0'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following query is used for Getting Categories and one news for each category. How
The following query returns the total amount of orders, per week, for the past
The following query used to grab all comments for a particular blog article and
Cursor cursor = resolver.query( Data.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] {String.valueOf(rawContactId)}, null); With PROJECTION being:
There's following web method that is being used in our legacy web service. [WebMethod(Description
I have managed to bring the following output with this query SELECT DISTINCT IF(purchaseproduct_customerid=0,contactperson,vendorname)
The following query is taking more than 25 seconds to complete: SELECT c.* ,
The following query matches the ID of electors with the corresponding elector from voting
The following query outputs the total logical reads on tables for the last 7
The following query: select unnest(Table2.L) as X, unnest(Table1.O) from Table1, Table2 where Table1.code =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.