optimize sql

Can I make these two subqueries into one?

select a.status_desc, a.dept_name, sku_count, fcr_count from
(select status_desc,
             count(distinct fpo_no || style || colour) sku_count
      from agi_016a_t1
      group by status_desc, dept_name) a
left join
(select status_desc,
              count(distinct fpo_no || style || colour) fcr_count
       from agi_016a_t1
       where fcr = 1  
       group by status_desc, dept_name) b on b.status_desc = a.status_desc and b.dept_name = a.dept_name;
Who is Participating?
tigin44Connect With a Mentor Commented:
select a.status_desc, a.dept_name, COUNT(*) AS sku_count, SUM(CASE WHEN fcr = 1 THEN 1 ELSE 0 END) AS fcr_count 
from agi_016a_t1
group by status_desc, dept_name

Open in new window

orauserAuthor Commented:
Can adjust the temp table to contain distinct fpo/style/colour instead of doing it here
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.