Hi,
I need some help with a sql query. I have a table that looks like this:
client gbytes backupdate files
abcd 10 2009-01-31 152
abcd 45 2009-02-19 450
abcd 77 2009-02-27 352
abcd 77 2009-03-03 351
bcde 400 2009-01-24 1000
bcde 1005 2009-02-24 1583
bcde 890 2009-02-24 1045
I need to extract all fields for every client but only when the client hits its Max gbytes size. I only want the client, backupdate and files fields output when I hit the MAX gbytes but I am getting multiple lines output for each client. Also, if
MAX gbytes matches for 2 different backupdates then I want the most recent backupdate record.
I have tried variations on the query below but can't seem to find the magic query. Any ideas what I am doing wrong? I also want to get the AVG gbytes in a separate query.
SELECT client,gbytes,backupdate,files
FROM my_table
INNER JOIN
(SELECT client as xclient, MAX(gbytes) AS xMaxBackup
FROM my_table
GROUP BY client)x
ON client = xclient AND gbytes = xMaxBackup
Thanks in advance for any help/ direction.
-ljs
I need some help with a sql query. I have a table that looks like this:
client gbytes backupdate files
abcd 10 2009-01-31 152
abcd 45 2009-02-19 450
abcd 77 2009-02-27 352
abcd 77 2009-03-03 351
bcde 400 2009-01-24 1000
bcde 1005 2009-02-24 1583
bcde 890 2009-02-24 1045
I need to extract all fields for every client but only when the client hits its Max gbytes size. I only want the client, backupdate and files fields output when I hit the MAX gbytes but I am getting multiple lines output for each client. Also, if
MAX gbytes matches for 2 different backupdates then I want the most recent backupdate record.
I have tried variations on the query below but can't seem to find the magic query. Any ideas what I am doing wrong? I also want to get the AVG gbytes in a separate query.
SELECT client,gbytes,backupdate,files
FROM my_table
INNER JOIN
(SELECT client as xclient, MAX(gbytes) AS xMaxBackup
FROM my_table
GROUP BY client)x
ON client = xclient AND gbytes = xMaxBackup
Thanks in advance for any help/ direction.
-ljs