please help me to make a query.I need the total of 3 counted columns in one query as a result, here is my option:
select region, count(s_code), count(b_code), count(d_code), sum(count(s_code, b_code, d_code)) as total
from shilpy
group by region
order by region
3
Answers
In this query, we first select the region column and then use the COUNT() function to count the occurrences of s_code, b_code, and d_code. We give each counted column an alias (s_code_count, b_code_count, d_code_count) to make it easier to reference in the result. Finally, we calculate the total count by summing up the individual counts using the + operator and give it the alias total_count. The GROUP BY clause groups the results by the region column, and the ORDER BY clause sorts the result by region
You can use a subquery to calculate specific counts, and then get the total of counts without having to rescan the entire table:
Demo here
If you only need the total, you can just sum it up inline: