Results 1 to 3 of 3

Thread: Group by

  1. #1
    Join Date
    May 2013
    Posts
    33

    Unanswered: Group by

    Code:
    SQL> Select city,description
            from employee;
    
    CITY                 DESCRIPTION
    -------------------- --------------------
    Toronto                 Programmer
    Vancouver             Tester
    Vancouver             Tester
    Vancouver             Manager
    Vancouver             Tester
    New York              Tester
    New York              Manager
    Vancouver            Tester
    
    8 rows selected.
    I m using oracle10g, SQL* Plus version 10.2

    I m getting output like this:

    Code:
    SQL> select city,description,count(*)
      2  from employee
      3  group by city,description;
    
    CITY                 DESCRIPTION            COUNT(*)
    -------------------- -------------------- ----------
    New York             Tester                       1
    New York             Manager                    1
    Vancouver           Tester                        2
    Vancouver           Manager                     1
    Toronto               Programmer                 1
    Vancouver           Tester                        1
    Vancouver           Tester                        1
    
    7 rows selected.
    But i need the output to be like this:

    Code:
    SQL> select city,description,count(*)
      2  from employee
      3  group by city,description;
    
    CITY                 DESCRIPTION            COUNT(*)
    -------------------- -------------------- ----------
    New York             Tester                       1
    New York             Manager                    1
    Vancouver           Tester                        3
    Vancouver           Manager                     1
    Toronto               Programmer                 1
    Last edited by satheeshsharma; 06-21-13 at 05:22.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    None of outputs you posted is properly aligned, all of these are too jumbled. Please, provide test case for the EMPLOYEE table (CREATE TABLE and INSERT INTO statements) so that we could reproduce what you claim.

    Meanwhile, see what
    Code:
    select trim(city), trim(description), count(*)
    from employee
    group by trim(city), trim(description)
    returns.

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    or fix your data so that it is entered properly.

Posting Permissions

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