Count/Sum Question

 2 Replies
 0 Subscribed to this topic
 22 Subscribed to this forum
Sort:
Author
Messages
FireGeek21
Veteran Member
Posts: 84
Veteran Member
    I have an id field in which the same id may exist multiple times for an employee. I have another field whose values are true or false. How can I count the number of true/falses for each unique id?
    Joe O'Toole
    Veteran Member
    Posts: 314
    Veteran Member
      This might get you close:

      select avg(EMPLOYEE), avg(ID), TF_FLAG, count(*)
      group by 1,2,3
      order by 1,2,3
      Adam Jacobson
      Veteran Member
      Posts: 69
      Veteran Member
        I'm not quite clear on your table layout.
        but, if you just want number of trues and falses for each id
        Select id, true/false, count(*)
        group by id, true/false
        Which would give you an output like
        12345 False 5
        12345 True 6
        12346 False 2
        12346 True 3

        you can also use a case statement to get it all on one line.
        But before I post that, is this what you're trying to do
        (you may also need the order by after the group by depending on your database)