Returning total rows for one column

I have query below that returns performance data for a specified SQL instance. The issue I am having is same textdata are returned for different time frames. I am looking for a way to sum up the same rows of textdata and return total cpu, duration, read, write.

Thank you for your assistance.

SELECT TOP 40 HostName, DatabaseName, ApplicationName,
       LoginName, CPU, TextData,
       Reads, Writes, Duration, StartTime, EndTime
FROM dbo.PerformanceTable 
WHERE  Duration > 10000

2 answers

  • answered 2021-09-11 18:03 Gordon Linoff

    Do you just want aggregation?

    SELECT TextData,
           SUM(Reads), SUM(Writes), SUM(Duration)
    FROM dbo.PerformanceTable 
    WHERE Duration > 10000
    GROUP BY TextData;

  • answered 2021-09-11 18:18 Kazi Mohammad Ali Nur

    Without sample data it's difficult to suggest a solution. If I understood you correctly you want total cpu, duration, read, write for each HostName, DatabaseName, ApplicationName, TextData regardless of their starttime or endtime.

    SELECT HostName, DatabaseName, ApplicationName,TextData,
           sum(CPU), sum(Reads), sum(Writes), sum(Duration)
    FROM dbo.PerformanceTable 
    group by HostName, DatabaseName, ApplicationName,TextData
    WHERE  Duration > 10000
    order by HostName, DatabaseName, ApplicationName,TextData

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum