If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL Assistance Needed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-06, 17:10
bunzo bunzo is offline
Registered User
 
Join Date: Apr 2005
Posts: 28
SQL Assistance Needed

The following SQL:

Select endpoint_label, Name, Avg(MetricValue)
From LM_MEM
Where (((Name = 'Availbytes') or (Name = 'PagesInputPerSec')) and Stat = 'AVG')
Group By endpoint_label, Name

produces two lines per endpoint_label.

I want to have one line per endpoint_label and I'm not successful in my attempts at this.
I'm trying for an end result such as:
endpoint_label, Availbytes, PagesInputPerSec
xxx1234xxxxxx, 6.123456, 15.446223
xxx1001xxxxxx, 6.673322, 15.977110

When I'm able to list each endpoint_label once, the Avg(MetricValue) for the two Names is incorrect and it's repeated for every row.
endpoint_label, Availbytes, PagesInputPerSec
xxx1234xxxxxx, 1.123456, 1.34876
xxx1001xxxxxx, 1.123456, 1.34876

Any assistance on this would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 01-23-06, 17:31
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Please post the table layout for LM_MEM
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-23-06, 21:28
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Maybe this works:

Code:
with endpoint_temp (endpoint_label,Availbytes,PagesInputPerSec) as
          (select endpoint_label,
                  case when Name = 'Availbytes' then MetricValue
                                                else 0
                  end as Availbytes,
                  case when Name = 'PagesInputPerSec' then MetricValue
                                                else 0
                  end as PagesInputPerSec
             from LM_MEM
            where NAME in ('Availbytes','PagesInputPerSec')
              and Stat = 'AVG')
 select endpoint_label,
        sum(Availbytes)       as "Availbytes" ,
        sum(PagesInputPerSec) as "PagesInputPerSec"
   from endpoint_temp
 group by endpoint_label;
Reply With Quote
  #4 (permalink)  
Old 01-24-06, 13:50
bunzo bunzo is offline
Registered User
 
Join Date: Apr 2005
Posts: 28
This helps, but is not giving me the proper Avg(MetricValue) for each of the two measurements. I'm not sure what it's actually displaying.

I'll play around with it and see if I can make it work.
Thanks for the directiion.


Quote:
Originally Posted by GertK
Maybe this works:

Code:
with endpoint_temp (endpoint_label,Availbytes,PagesInputPerSec) as
          (select endpoint_label,
                  case when Name = 'Availbytes' then MetricValue
                                                else 0
                  end as Availbytes,
                  case when Name = 'PagesInputPerSec' then MetricValue
                                                else 0
                  end as PagesInputPerSec
             from LM_MEM
            where NAME in ('Availbytes','PagesInputPerSec')
              and Stat = 'AVG')
 select endpoint_label,
        sum(Availbytes)       as "Availbytes" ,
        sum(PagesInputPerSec) as "PagesInputPerSec"
   from endpoint_temp
 group by endpoint_label;
Reply With Quote
  #5 (permalink)  
Old 01-24-06, 13:57
bunzo bunzo is offline
Registered User
 
Join Date: Apr 2005
Posts: 28
I changed the "else 0" to "else null"
This seems to give me the results I was looking for.

Thanks!

Quote:
Originally Posted by bunzo
This helps, but is not giving me the proper Avg(MetricValue) for each of the two measurements. I'm not sure what it's actually displaying.

I'll play around with it and see if I can make it work.
Thanks for the directiion.
Reply With Quote
  #6 (permalink)  
Old 01-24-06, 14:11
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Because you didn't supply the original DDL needed to recreate the table and didn't give some data samples my code was a bit of a guess. If you do that the next time the answer will most likely be more accurate.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On