stephaniem712
asked on
sql code
Using sql, how would i check to see if a firm has multiple auditors in a certain period, say 2004 - 2007?
I have firm number, fiscal year, and auditor key. If there are more than one auditor key during the time from 2004-2007 I need to delete the firm.
Thank you!
I have firm number, fiscal year, and auditor key. If there are more than one auditor key during the time from 2004-2007 I need to delete the firm.
Thank you!
ASKER
Hi,
Thanks, but I am going to have data that looks like this.. What I need to be able to do is determine that firm number 4321 has multiple auditors or changed auditors during the sample period. firm number 1234 did not change auditors or have multiple auditors. If the firm has multiple auditors, I want to delete delete those firms.
Firm Number Fiscal Year Auditor Key
1234 2004 1
1234 2005 1
1234 2006 1
4321 2004 1
4321 2005 1
4321 2006 2
4321 2007 2
Thanks, but I am going to have data that looks like this.. What I need to be able to do is determine that firm number 4321 has multiple auditors or changed auditors during the sample period. firm number 1234 did not change auditors or have multiple auditors. If the firm has multiple auditors, I want to delete delete those firms.
Firm Number Fiscal Year Auditor Key
1234 2004 1
1234 2005 1
1234 2006 1
4321 2004 1
4321 2005 1
4321 2006 2
4321 2007 2
OK, I see. Then the query will be simpler:
SELECT distinct firmNumber
FROM firms
WHERE fiscalYear >= 2004 and fiscalYear <= 2007 and AuditorKey > 1
To delete the firms run this query:DELETE FROM firms where firmNumber in(SELECT distinct firmNumber
FROM firms
WHERE fiscalYear >= 2004 and fiscalYear <= 2007 and AuditorKey > 1)
(Please run the delete statement after you are absolutely sure you want to delete them)
ASKER
Sorry,
I should be more clear. The auditor key identifies each auditor. So, if there is more than one unique auditor for each firm during my sample period, I need to delete those firms.
So, in my example, firm 1234 is fine because it had only one auditor the whole time -- auditor #1 whereas firm 4321 had two auditors --- auditor #1 and auditor #2.
auditor key #1 could be PriceWaterhouse and auditor key #2 could be KPMG. If a firm has more than one auditor during my sample period, I need to delete those firms.
I should be more clear. The auditor key identifies each auditor. So, if there is more than one unique auditor for each firm during my sample period, I need to delete those firms.
So, in my example, firm 1234 is fine because it had only one auditor the whole time -- auditor #1 whereas firm 4321 had two auditors --- auditor #1 and auditor #2.
auditor key #1 could be PriceWaterhouse and auditor key #2 could be KPMG. If a firm has more than one auditor during my sample period, I need to delete those firms.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad yuo have managed to figure it out. Just closing your question and mark your answer as an answer
ASKER
Tested my code and it worked.
Open in new window