I am a novice and need some help with this sql query. I have a sql table that contains records of tape media written to, the date written to and whether the media is onsite/offsite and the date it was discovered offsite. It has other fields but these 4 are what is of importance. Sample info in the table is:
Media DATE_Written Offsite Discovered_OFFSITE_DATE
tape01 01-03-2009 N NULL
tape01 01-04-2009 N NULL
tape01 01-05-2009 N NULL
tape99 01-03-2009 Y 01-06-2009
tape99 01-04-2009 Y 01-06-2009
tape99 01-05-2009 Y 01-06-2009
tape33 01-04-2009 Y 01-08-2009
tape33 01-05-2009 Y 01-08-2009
tape99 01-21-2009 Y 01-25-2009
tape99 01-22-2009 Y 01-25-2009
I need to query this table and get a count of media written in month of Jan 2009 and another distinct count for every time a media was sent offsite.
So, in the above sample, 10 medias are written to but the offsite media count would be only 3 medias(not 6). tape99 was written to on 5 different days and sent offsite 2 different dates. I believe there must be some sub-query using that discovery date of counting distinct media moving offsite but I have no idea how to do it.
Any help/ direction would be great. Thanks.
ljs
Media DATE_Written Offsite Discovered_OFFSITE_DATE
tape01 01-03-2009 N NULL
tape01 01-04-2009 N NULL
tape01 01-05-2009 N NULL
tape99 01-03-2009 Y 01-06-2009
tape99 01-04-2009 Y 01-06-2009
tape99 01-05-2009 Y 01-06-2009
tape33 01-04-2009 Y 01-08-2009
tape33 01-05-2009 Y 01-08-2009
tape99 01-21-2009 Y 01-25-2009
tape99 01-22-2009 Y 01-25-2009
I need to query this table and get a count of media written in month of Jan 2009 and another distinct count for every time a media was sent offsite.
So, in the above sample, 10 medias are written to but the offsite media count would be only 3 medias(not 6). tape99 was written to on 5 different days and sent offsite 2 different dates. I believe there must be some sub-query using that discovery date of counting distinct media moving offsite but I have no idea how to do it.
Any help/ direction would be great. Thanks.
ljs