tfcallahan
asked on
Query to get total counts of multiple bit fields in each row
I have a table with the following fields
FK_ID - foriegn key ID
PK_ID - unique PK
REVIEWED - bit
REJECTED - bit
I would like a query that, for a particular FK_ID value, returns a count of:
a. total number of rows matching the FK_ID
b. total number of rows matching the FK_ID that have REVIEWED=1
c. total number rows matching the FK_ID that have REJECTED=1
I'm sure the answer is already out there but a search didn't find this specific case.
Thanks,
Tim
FK_ID - foriegn key ID
PK_ID - unique PK
REVIEWED - bit
REJECTED - bit
I would like a query that, for a particular FK_ID value, returns a count of:
a. total number of rows matching the FK_ID
b. total number of rows matching the FK_ID that have REVIEWED=1
c. total number rows matching the FK_ID that have REJECTED=1
I'm sure the answer is already out there but a search didn't find this specific case.
Thanks,
Tim
SELECT 'Total', COUNT(*) FROM table WHERE FK_ID=x
UNION ALL
SELECT 'REVIEWED',COUNT(*) FROM table WHERE FK_ID=x AND REVIEWED=1
UNION ALL
SELECT 'REJECTED',COUNT(*) FROM table WHERE FK_ID=x AND REJECTED=1
UNION ALL
SELECT 'REVIEWED',COUNT(*) FROM table WHERE FK_ID=x AND REVIEWED=1
UNION ALL
SELECT 'REJECTED',COUNT(*) FROM table WHERE FK_ID=x AND REJECTED=1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just had to swap the Reviewed and Rejected expression labels and works like a charm.
Thanks!
Thanks!
lol - tired eyes. Must be bed time ;)
Glad to help.
Glad to help.
ASKER
FK_ID Total Rejected Reviewed
1234 6 1 5