Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    6

    Unanswered: COUNTing 2 columns within one table

    I am trying to COUNT the bumber of entrants for 2 columns within the same table but the second COUNT has to have a WHERE clause.

    SELECT COUNT(winID), count(isClaimed) FROM winners WHERE isClaimed =1

    Here I am trying to return the entire number of records (winID - which is an auto-increment field) but only return the number of records from the column isClaimed wher the value = 1.

    I am completely stumped. Anyone any ideas?

    Thanks.

  2. #2
    Join Date
    Mar 2004
    Posts
    480

    Re: COUNTing 2 columns within one table

    Originally posted by alexh
    I am trying to COUNT the bumber of entrants for 2 columns within the same table but the second COUNT has to have a WHERE clause.

    SELECT COUNT(winID), count(isClaimed) FROM winners WHERE isClaimed =1

    Here I am trying to return the entire number of records (winID - which is an auto-increment field) but only return the number of records from the column isClaimed wher the value = 1.

    I am completely stumped. Anyone any ideas?

    Thanks.
    SELECT COUNT(winID) as winIDtotal,
    sum(case when isClaimed=1 then 1 else 0 end) as isClaimedtotal
    FROM winners;

Posting Permissions

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