I want to display record in this format PATIENT_CODE,gender,Malecount,femalecount

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Swapnil Mestry

    I want to display record in this format PATIENT_CODE,gender,Malecount,femalecount

    I want to display record in this format:
    PATIENT_CODE,ge nder,Malecount, femalecount

    Code:
    Select PATIENT_CODE,gender,count(*)
    From BABY_MASTER Where Patient_Code='KBB-04-2010-96'
    group by PATIENT_CODE,SEX
    This query shows Patient_code,ge nder,count, if there is 4 record for particular patient.

    I want to display record in one row that should be in this format:
    Patient_code,Ma lecount,femalec ount

    Can anybody help me with the solution?

    Thanks in advance.
    Last edited by Frinavale; Nov 24 '10, 02:06 PM. Reason: Added code tags.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What's the name of the column for gender? Is it Gender or Sex? You have gender in the select list but Sex in Group By.

    ~~ CK

    Comment

    • Sandeep M

      #3
      select PATIENT_CODE,su m(Fcount) as Fcount,sum(Mcou nt) as Mcount from
      (
      Select PATIENT_CODE,ca se gender when 'F' then 1 else 0 end as Fcount,case gender when 'M' then 1 else 0 end as Mcount
      From BABY_MASTER Where Patient_Code='K BB-04-2010-96'
      ) cur group by PATIENT_CODE

      Comment

      Working...