Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Union Queries with totals, data from same table

User_JHBB3Feb 16 2021 — edited Feb 16 2021

Hi, I am trying to combine 2 queries that are counting records, but the output is confusing me.

The queries, individually, simply count how many records match a criteria, and they work individually. But when I combine them via union, the totals are changing. I have tried union all. The data for both queries is in the same table.

Basically, my query is counting how many people have done training, vs how many people havent, and I need it in a 2 column, 2 row format. I need it in this format for an Apex chart. The criteria is literally the opposite of each other.

SELECT 'Completed' AS TEXT
, COUNT(*) AS TOTAL
FROM table1
WHERE training = 'Completed'
UNION ALL
SELECT 'Not Completed' AS TEXT
, COUNT(*) AS TOTAL
FROM table1
WHERE training != 'Completed'

This post has been answered by Frank Kulash on Feb 16 2021
Jump to Answer
Comments
Post Details
Added on Feb 16 2021
6 comments
1,746 views