SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Summarizing multiple colummns from a table


Summarizing multiple colummns from a table

Author
Message
c2k
c2k
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 127
Table:


IPADDRESSSTR, NBNAME, FaultlineID, CVE, OPEN, CLOSED, STATUS
172.0.0.1, HOST1, 3623, CVE-2013-1212, 1, 0, vulnerable
172.0.0.2, HOST2, 3624, CVE-2013-1213, 0, 1, not vulnerale
172.0.0.3, HOST3, 3624, CVE-2013-1213 0, 1, not vulnerale
172.0.0.4, HOST4, 3624, CVE-2013-1213 1, 0, not vulnerale
172.0.0.5, HOST5, 3624, CVE-2013-1213 0, 1, not vulnerale



I would like to count the values in the OPEN and CLOSED column and calculate a total for each FID and CVE combination. The output should look like this:


FaultlinID, CVE, OPEN, CLOSED, TOTAL
3623, CVE-2013-1212, 3623, 1, 0, 1
3624, CVE-2013-1213, 3624,1,2,3



I've tried the following SQL script, however, the counts are obviously wrong.


SELECT faultlineid, cve, SUM([OPEN]), SUM({CLOSED}),SUM([OPEN])+SUM({CLOSED}) AS TOTAL FROM TABLE
GROUP BY faultlineid, cve



How should I approach this problem in order to get accurate column counts?
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16747 Visits: 19118
Why do you have this

FaultlinID, CVE, OPEN, CLOSED, TOTAL
3623, CVE-2013-1212, 3623, 1, 0, 1
3624, CVE-2013-1213, 3624,1,2,3

Instead of this?

FaultlinID, CVE, OPEN, CLOSED, TOTAL
3623, CVE-2013-1212, 3623, 1, 0, 1
3624, CVE-2013-1213, 3624,1,3,4



Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
c2k
c2k
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 127
An error with my math:

This is correct:

FaultlinID, CVE, OPEN, CLOSED, TOTAL
3623, CVE-2013-1212, 3623, 1, 0, 1
3624, CVE-2013-1213, 3624,1,3,4

ty
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16747 Visits: 19118
So the output from your query is correct?
The only difference I see is that you repeat the FID


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search