10-18-08, 07:14 #1Registered User
- Join Date
- Jul 2007
Unanswered: Attempting to get multiple counts from table, but with column criteria.
I am attempting to get a list of counts from several columns, but where columns are set to a certain value.
See below for some example data.
ID,Site,Type,State,Status,StartTime,Description 1,site1,0,3,0,1224279787,Site1_Unix 2,site1,0,3,0,1224279782,Site1_Unix 3,site1,0,3,0,1224279770,Site1_Unix 4,site1,0,3,0,1224279741,Site1_Unix 5,site1,0,3,1,1224279680,Site1_Windows 6,site1,0,3,0,1224279678,Site1_Windows 7,site2,0,3,1,1224280274,Site2_Windows 8,site2,0,3,1,1224279614,Site2_Windows 9,site2,0,3,1,1224279594,Site2_Windows 10,site2,0,3,0,1224279582,Site2_Unix 11,site2,0,3,1,1224279575,Site2_Windows
Active = (State = 1)
Queued = (State = 0)
Completed = (State = 3 & Status = 0)
Failed = (State = 3 & Status > 0)
Retry - (State = 2)
There are a couple of other clauses, but these can go into the Where statement as they are global.
type = 0
description not like "%Catalog%" or not like "%logisnap%"
StartTime > 18:00 last business day in epoch time.
Can this be done in one statement?
10-18-08, 14:58 #2Annie's Dog Walker
Provided Answers: 6Code:
- Join Date
- Nov 2004
- on the wrong server
SELECT X.SITE,SUM(X.ACTIVE) AS ACTIVE,SUM(X.Queued) AS QUEUED--, ETC... FROM ( SELECT SITE, (CASE WHEN STATUS=1 THEN 1 ELSE 0 END) AS Active, (CASE WHEN STATUS = 0 THEN 1 ELSE 0 END) AS Queued--,ETC.... FROM YourTable) X GROUP BY X.SITEIf one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.