Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Unanswered: selecting count values for

    Here is the problem

    Table schema is:

    ID, UID, BUILDING, TIME;

    I want to count how many are rows contains some BUILDING with some value in a single query. I can`t explain it very good. See the example to understant what i want.

    EXAMPLE

    1, 2, 0, some time;
    2, 2, 0, some time;
    3, 2, 0, some time;
    4, 2, 1, some time;
    5, 2, 1, some time;
    6, 2, 3, some time;

    The query must return: 3 (O) AND 2 (1) AND 1 (3)

    Thank you!
    Marush Denchev

  2. #2
    Join Date
    Jan 2006
    Posts
    32
    use GROUP BY.



    .

  3. #3
    Join Date
    Oct 2003
    Location
    Rhodesia
    Posts
    28
    Quote Originally Posted by antubis
    Here is the problem

    Table schema is:

    ID, UID, BUILDING, TIME;

    I want to count how many are rows contains some BUILDING with some value in a single query. I can`t explain it very good. See the example to understant what i want.

    EXAMPLE

    1, 2, 0, some time;
    2, 2, 0, some time;
    3, 2, 0, some time;
    4, 2, 1, some time;
    5, 2, 1, some time;
    6, 2, 3, some time;

    The query must return: 3 (O) AND 2 (1) AND 1 (3)

    Thank you!
    Marush Denchev
    Try this
    Code:
     SELECT A.BUILDING,COUNT(A.BUILDING) AS COUNTS FROM TABLE A 
         WHERE A.BUILDING NOT NULL
         GROUP BY BUILDING
         ORDER BY COUNTS DESC;

Posting Permissions

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