Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Counting occurances for values over a given size?

Author  Topic 

pwjm
Starting Member

4 Posts

Posted - 2011-07-18 : 12:08:33
My boss asked me to write up a report for our network management software. It's based off MSSQL and While I'm okay at it, I'm no pro at all.

In my bosses words:
quote:
"a report that shows trending on packet loss or the number of times packet loss has occurred may be useful showing a troublesome circuit that has issues popping up from time to time"


so lets say over a given period of time (one month) the packet loss changes often. I'd like to be able to craft a report that shows how many times the packet-loss has reached a value above 5% for the month.

If anyone can point me in the right direction for finding a function of group of functions that will help me achieve this it would be greatly appreciated.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-18 : 12:33:20
Could you provide some sample data from the table and what you'd expect the output should be for that sample?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

pwjm
Starting Member

4 Posts

Posted - 2011-07-18 : 12:38:41
http://imgur.com/sCXLC

So that's a report that was generated by a wizard. It's kind of what I need, but It's only a recap for the max packet loss for the month. What I need specifically is how many times over the course of the month the packet loss has gone above a certain level.

hope that helps. Sorry about the blurring, it's potentially confidential info.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-18 : 12:51:46
I was looking for some data to work with. Please read this article and then re-post.

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

pwjm
Starting Member

4 Posts

Posted - 2011-07-18 : 13:17:54
Thanks Jim.

The info in that picture I posted is all I really have access too. I'm honestly not really looking for anyone to script something for me. I just need to know what SQL commands would be used to achieve the concept that I outlined. If anyone reading this has an idea how it could be achieved, I only need to be pointed in the right direction and I'll be able to figure it out. Just take a guess at it and use pseudo script if you have to.
Go to Top of Page

pwjm
Starting Member

4 Posts

Posted - 2011-07-19 : 12:17:23
Someone from another forum helped me out. Here's the result:

SELECT
N1.Caption as NodeName,
SUM(CASE
WHEN R1.PercentLoss > 0
THEN 1
ELSE 0
END) as Greater_Than_0,
SUM(CASE
WHEN R1.PercentLoss > 50
THEN 1
ELSE 0
END) as Greater_Than_50
FROM Nodes N1
INNER JOIN ResponseTime R1
ON N1.NodeID = R1.NodeID
GROUP BY N1.Caption
ORDER BY N1.Caption

Would give three columns along the lines of:

NodeName Greater_Than_0 Greater_Than_50
Node1 10 5
Node2 20 0
etc...

This would cover the entire date range in your data which is probably not very useful in day to day use so you would probably want to add a date range in (as a where statement) or (more likely) add in another column to show the month.

If the count / total is misleading (e.g. packet losses happen in clusters) then you might want something like:

SELECT t.NodeName,
COUNT(*) as Occs
FROM
(
SELECT
YEAR([DateTime]) as Y,
MONTH([DateTime]) as M,
N1.Caption as NodeName,
MAX(R1.PercentLoss) AS Max_Packet_Loss
FROM Nodes N1
INNER JOIN ResponseTime R1
ON N1.NodeID = R1.NodeID
GROUP BY YEAR([DateTime]) ,
MONTH([DateTime]),
N1.Caption
HAVING MAX(R1.PercentLoss)>50
) t
GROUP BY t.NodeName
Go to Top of Page
   

- Advertisement -