SQL Query assistance

Status
Not open for further replies.
I've been tasked to write some SQL queries for some custom reporting out of our Backup Software.
So far I have got everything down but am struggling to design the last one.

Here is the business requirement:
The last successful backup for each client (date).

So output:
Code:
client1    4/1/2010
client2    4/2/2010
client3    4/1/2010

table:
Code:
jobid, clientname, starttime, endtime, status
1    , client1   , 3/20/2010, 3/21/2010, Success
2    , client2   , 3/21/2010, 3/22/2010, Fail
3    , client1   , 3/21/2010, 3/22/2010, Success
4    , client2   , 3/20/2010, 3/21/2010, Success

In other words there are 1000's of lines of job history with all fields I would need.
I have tried some sort of query with subquery but having trouble conceptially thinking this through.
It needs to kind of have a get list of all clients, per each client find the starttime when status = success.

I will actually once I figure this out combine this with a query which returns:
client, Type, Status
client1, Windows, Success

I want to add the column LastGood. I figured I write that query separate first to 'figure' it out.
 

Fristie Blade

Ars Tribunus Militum
1,722
Subscriptor++
Just a question concerning the business requirement: what do you need to do if there is a client whose backup always fails and never reaches an initial success?
Your client will not be shown at all due to the restriction.
Could be acceptable, or otherwise you might want to show a record for the client as well without a date in your reporting?

You will probably not encounter the scenario, but I always think in exceptional data when seeing aggregation functions and joining tables.
 
Status
Not open for further replies.