Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 18th, 2003, 04:15 PM
vidigiani vidigiani is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 6 vidigiani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Generating statistics on a ternary mapping

I have a ternary mapping as follows

resource <-> resource_state <-> system

Each resource can be mapped to multiple systems. For each relationship there is a state that indicates the state of the resource on the system.

I want to generate a table that tells me how many systems are active and how many are passive. A system is active if it at least one resource has an "Online" state for the system. A system is passive if no resources have an "Online" state for the system.

Getting the number of active systems is pretty trivial. The problem I am having is generating the number of passive systems (which may also be trivial, but not yet to me ).

Reply With Quote
  #2  
Old November 18th, 2003, 10:18 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 12 m 27 sec
Reputation Power: 56
How many possible values for state can any one system have? Is it just "Online" or "Offline"? (IE boolean)

Reply With Quote
  #3  
Old November 19th, 2003, 08:33 AM
vidigiani vidigiani is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 6 vidigiani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
There are four states right now, but that could change down the road.

I did find a solution last night. The actual problem was slightly more complicated, where the resource and systems were contained in an application group. I wanted to create aggregates of the active systems and passive systems on the app group. I did this for "passive systems" with:

Code:
having sum(casewhen(resource_state.state = 'Online', 1, 0)) = 0
in a subselect.

Not sure that is the most optimal approach, but it works.

Reply With Quote
  #4  
Old November 19th, 2003, 09:46 AM
vidigiani vidigiani is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 6 vidigiani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Figured I would post an even better solution I cam up with (in case someone might run into a similar problem). Basically, I get the total and the active systems and using subtraction get the passive systems. Way fewer lines of SQL and the performance is much better as well.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Generating statistics on a ternary mapping


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT