Skip to Main Content

APEX

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!

How to add static data in count() without union

Jian-cdoMay 5 2022

Hello,
I have a query like:
select case when gender is null then 'Unknown' else Gender end gender, count(1) genderCount
from table_1
group by gender
=============
table_1 has dynamic data. Then I have another table_2, which has static data. Say, the gender count is always like these after running the query:
Gender GenderCount
male 2700
female 2100
unknown 300
Now I wonder how I can directly add three numbers into the count without using union (run the query on table2 again). My current query is this way, but I don't like the second part will be run again every time user refreshes the page. I'm not going to provide the information to create a table since I just want an idea on how to tune the query. Thanks.
select gender, count(1) genderCount
from (
select case when gender is null then 'Unknown' else Gender end gender
from table_1
union all
select gender from table_2 )
group by gender

Comments

Post Details

Added on May 5 2022
1 comment
140 views