Consider the following tables which reside on a sql 7 db
date servername dbname dbid groupid groupname fileid filesize maxfilesize growth name
--------------------------- ------------------ ----------------------------------- ----------- ----------- -------------------- ----------- -------------------- -------------------- ----------- --------------------------------------------
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 PRIMARY 1 4.00 .00 10 abcd_Data
2001-07-25 14:51:00.000 EUS9808058 abcd 7 NULL log 2 6.24 .00 10 abcd_Log
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 PRIMARY 3 6.00 .00 10 abcd2
2001-07-25 14:51:00.000 EUS9808058 abcd 7 2 secondary 4 5.00 .00 10 abcd1
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 PRIMARY 1 70.00 .00 10 testsplit_Data
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 NULL log 2 30.75 .00 10 testsplit_Log
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 PRIMARY 3 60.00 .00 10 testsplit_data1
(7 row(s) affected)
date servername dbname dbid groupid reserved used
--------------------------- ------------------ ----------------------------------- ----------- ----------- -------------- --------------
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 6.80 5.63
2001-07-25 14:51:00.000 EUS9808058 abcd 7 2 3.64 3.57
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 16.86 14.39
(3 row(s) affected)
I am trying to create a sql stmt that will summarize filesize (table1) with a summary of reserved (table2) for each database for a given date. so, it is grouped by date, dbname and servername. as well, I want to include a percent used....
at any rate, the problem is that since the groupid does not match up, the summaries get a little screwed up (there is more than on group id on table1, but only 1 groupid in table 2). ultimately, i have nothing to join by so that i can do summaries properly.
my solution to this point is the following sql, which works but will only work for one db at a time which means i need a cursor. I am trying to build a sql that will summarize then entire table for all dbs for a given date.
select date,servername,dbname,
(select sum(reserved) from dbusage where dbname='abcd'and date=(select max(date) from dbusage)),
sum(filesize)
from dbstats a where date=(select max(date) from dbstats)
and groupid > 0 and dbname='abcd'
group by date,servername,dbname
ideas? Paul
date servername dbname dbid groupid groupname fileid filesize maxfilesize growth name
--------------------------- ------------------ ----------------------------------- ----------- ----------- -------------------- ----------- -------------------- -------------------- ----------- --------------------------------------------
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 PRIMARY 1 4.00 .00 10 abcd_Data
2001-07-25 14:51:00.000 EUS9808058 abcd 7 NULL log 2 6.24 .00 10 abcd_Log
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 PRIMARY 3 6.00 .00 10 abcd2
2001-07-25 14:51:00.000 EUS9808058 abcd 7 2 secondary 4 5.00 .00 10 abcd1
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 PRIMARY 1 70.00 .00 10 testsplit_Data
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 NULL log 2 30.75 .00 10 testsplit_Log
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 PRIMARY 3 60.00 .00 10 testsplit_data1
(7 row(s) affected)
date servername dbname dbid groupid reserved used
--------------------------- ------------------ ----------------------------------- ----------- ----------- -------------- --------------
2001-07-25 14:51:00.000 EUS9808058 abcd 7 1 6.80 5.63
2001-07-25 14:51:00.000 EUS9808058 abcd 7 2 3.64 3.57
2001-07-25 14:51:00.000 EUS9808058 testsplit 5 1 16.86 14.39
(3 row(s) affected)
I am trying to create a sql stmt that will summarize filesize (table1) with a summary of reserved (table2) for each database for a given date. so, it is grouped by date, dbname and servername. as well, I want to include a percent used....
at any rate, the problem is that since the groupid does not match up, the summaries get a little screwed up (there is more than on group id on table1, but only 1 groupid in table 2). ultimately, i have nothing to join by so that i can do summaries properly.
my solution to this point is the following sql, which works but will only work for one db at a time which means i need a cursor. I am trying to build a sql that will summarize then entire table for all dbs for a given date.
select date,servername,dbname,
(select sum(reserved) from dbusage where dbname='abcd'and date=(select max(date) from dbusage)),
sum(filesize)
from dbstats a where date=(select max(date) from dbstats)
and groupid > 0 and dbname='abcd'
group by date,servername,dbname
ideas? Paul