hi guys
I need to do a count on a column in my table but i have to check for a condition first.
Here is my sample data
Providerdate | Region | DHB | DHBName | PHO | PHOName | Practice | Practicename | PracticeAddress | Practice_Startdate | Practice_Enddate | Practitioner | PractitionerName | Practitioner_Startdate | Practitioner_Enddate | Locum |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 29201 | Geraldine Victoria MacKenzie Jordan | 8/06/2005 | 31/10/2005 | no |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 22079 | Glenn Morton Colquhoun | 1/03/2006 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 14121 | Meaburn Charles Staniland | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 9877 | Philip White | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 11678 | Susan Prudence Wilson | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000045 | Horatepai | 15 Epiha Street, Paraparaumu | 1/07/2003 | | 3881 | Wilfred Travis Wilson | 5/01/2002 | | yes |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 22742 | Adrian Howard Beaumont Gilliland | 13/01/2005 | 28/10/2005 | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 18188 | Amanda Mary Clarke | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 32909 | Andre Honda Garib | 29/12/2005 | | no |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 13042 | Christopher Alan Fawcett | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 16556 | Jennifer Maree O'Donnell | 1/07/2003 | 22/12/2005 | YES |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000052 | Paraparaumu Medical Centre | 92-94 Kapiti Road, Paraparaumu | 1/07/2003 | | 13650 | Timothy Stapleton Smith | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000046 | Paul Norton Surgery | 51 Kapiti Road, Paraparaumu | 1/07/2003 | | 14621 | Paul Stephen Norton | 1/07/2003 | | NO |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000053 | Raumati Road Surgery | 23 Raumati Road, Raumati Beach, Paraparaumu | 1/07/2003 | | 11202 | Katherine Dana Stone | 3/10/2005 | 7/10/2005 | yes |
1/01/2006 | Central | 091 | Capital & Coast DHB | 585171 | Kapiti PHO-585171 | 585171_0000053 | Raumati Road Surgery | 23 Raumati Road, Raumati Beach, Paraparaumu | 1/07/2003 | | 13048 | Robyn Lynette Crow | 1/07/2003 | | NO |
now i have to add two new columns as LocumYes and LocumNo
In Locumyes column I have to count the number of 'yes' in the locum column grouped by practitioner and in locumno i have to count the number of 'no' for that practitioner.
The situation is a practitioner can work on more than one practice and he can work as a 'yes' locum in one,'no' locum' in another or vice versa.It can be of any sort of combination.
so I have to do a query which should group by practitioner and count the number of yes and no for each practitioner..
Thanks
Mita
Hi. You can do this with subqueries included in the SELECT statement.
Let's suppose your table is named tblPractices:
SELECT Practicioner,
(SELECT COUNT(Locum) FROM tblPractices LocumYes WHERE Locum = 'yes' AND LocumYes.Practicioner = tblPractices.Practicioner) AS NumYes,
(SELECT COUNT(Locum) FROM tblPractices LocumNo WHERE Locum = 'no' AND LocumNo.Practicioner = tblPractices.Practicioner) AS NumNo
FROM tblPractices
GROUP BY Practicioner
Tony Alicea
http://www.theabstractionpoint.com
clarity of mind and creativity in application software development...
No comments:
Post a Comment