September 27, 2006 at 3:05 pm
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
September 27, 2006 at 4:01 pm
Mita,
I hope this is what u wanted. Please let me know if this is not right.
Select Providerdate,Region,DHB,DHBName,PHO,PHOName,Practice,Practicename,
PracticeAddress,Practice_Startdate,Practice_Enddate,Practice_Test.Practitioner,
PractitionerName,Practice_Test.Practitioner_Startdate,Practitioner_Enddate
,YCount,NCount
from Practice_Test INNER JOIN
(
Select Practitioner, sum(Case when Upper(Locum) ='YES' Then 1 Else 0 End) as YCount,
sum(Case when Upper(Locum) ='NO' Then 1 Else 0 End) as NCount
from Practice_Test
group by Practitioner
  PractitionerGroup ON Practice_Test.Practitioner = PractitionerGroup.Practitioner
Thanks
Sreejith
September 27, 2006 at 5:35 pm
hi Sreejith
thanks for the help
i tried this query but there is some syntax error which says- incorrect synax near group.
"PractitionerGroup ON Practice_Test.Practitioner = PractitionerGroup.Practitioner"
I could not understand this above statement.
What do you mean by practitionergroup??
September 27, 2006 at 6:54 pm
"Select Practitioner, sum(Case when Upper(Locum) ='YES' Then 1 Else 0 End) as YCount,
sum(Case when Upper(Locum) ='NO' Then 1 Else 0 End) as NCount
from Practice_Test
group by Practitioner"
when i try this bit, it works but the part above the inner join,something wrong with it.
September 28, 2006 at 2:44 am
I believe the closing brace after group by Practitioner is missing, PractitionerGroup is the derived table and the syntax should work without any errors.
Prasad Bhogadi
www.inforaise.com
September 28, 2006 at 10:41 am
Agree re closing paren. Looks like something replaced it with a smiley face emoticon! Pretty dumb "feature" in a technically oriented forum
September 28, 2006 at 2:24 pm
I didn't realise that ) was repalced with smily face. These should be plain text box without emiticons.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply