Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    13

    Unanswered: GROUP BY gives me errors

    I am trying to do this with ORACLE but I don't get it :-/

    I have a table "CPU":
    +---------+----------+--------+----------+-------------+
    | HOST_ID | BOARD_NO | CPU_NO | CPU_FREQ | ECACHE_SIZE |
    +---------+----------+--------+----------+-------------+
    | 8000 | 1 | 1 | 12 | 5 |
    | 8000 | 1 | 2 | 12 | 5 |
    | 8000 | 1 | 3 | 12 | 5 |
    | 8000 | 1 | 4 | 12 | 5 |
    | 8000 | 2 | 5 | 112 | 5 |
    | 8000 | 2 | 6 | 112 | 5 |
    | 8000 | 3 | 7 | 1112 | 55 |
    | 8000 | 4 | 8 | 55 | 65 |
    +---------+----------+--------+----------+-------------+

    Using this statement:
    SELECT BOARD_NO, count(BOARD_NO), CPU_FREQ,ECACHE_SIZE
    FROM `CPU` where HOST_ID ='8000' GROUP BY BOARD_NO

    it should give me this result :

    +----------+-----------------+----------+-------------+
    | BOARD_NO | count(BOARD_NO) | CPU_FREQ | ECACHE_SIZE |
    +----------+-----------------+----------+-------------+
    | 1 | 4 | 12 | 5 |
    | 2 | 2 | 112 | 5 |
    | 3 | 1 | 1112 | 55 |
    | 4 | 1 | 55 | 65 |
    +----------+-----------------+----------+-------------+


    However this does not work. It works fine in MySQL but I need it for Oracle.
    If anybody has an idea I would very much appreciate it.

    Thanks,
    kromo

  2. #2
    Join Date
    Apr 2003
    Location
    Greenville, SC (USA)
    Posts
    1,155
    SELECT BOARD_NO, CPU_FREQ,ECACHE_SIZE, count(*)
    FROM `CPU` where HOST_ID ='8000'
    GROUP BY BOARD_NO, CPU_FREQ,ECACHE_SIZE

    HTH
    Gregg

  3. #3
    Join Date
    Dec 2003
    Posts
    13
    Yes indeed. Exactly what I was looking for.

    Thanks a lot!
    kromo

  4. #4
    Join Date
    Nov 2003
    Location
    down on the cube farm, left then right then another left
    Posts
    467
    Originally posted by kromo
    Yes indeed. Exactly what I was looking for.

    Thanks a lot!
    kromo
    In case you are interested the reason your query was failing was that you where running a "grouping" function "count()" in your query so Oracle expects all the columns to have a "grouping" function. Hence that is why you needed to but group by for all the "other" columns.

Posting Permissions

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