Results 1 to 4 of 4

Thread: Self Join

  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Unanswered: Self Join

    I have table like

    Std_id profile
    1 HIGH
    2 HIGH
    3 MEDIUM
    4 LOW
    5 HIGH
    6 MEDIUM

    Now i want to get a report that should inform me the number of students in HIGH, MEDIUM and LOW profile....


    Please Help me

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Select profile, count(*)
    from table
    where profile IN ('HIGH', 'MEDIUM', 'LOW')
    group by profile;
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Feb 2004
    Posts
    2
    Thanks For the Reply but, i want that in the following format.


    HIGH MEDIUM LOW
    2 2 5

  4. #4
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Select
    SUM(CASE WHEN profile = 'HIGH' THEN AMT ELSE 0 END) As "HIGH",
    SUM(CASE WHEN profile = 'MEDIUM' THEN AMT ELSE 0 END) As "MEDIUM",
    SUM(CASE WHEN profile = 'LOW' THEN AMT ELSE 0 END) As "LOW"
    from
    (Select profile, count(*) as "AMT"
    from table
    where profile IN ('HIGH', 'MEDIUM', 'LOW')
    group by profile);
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •