?
Solved

optimize sql

Posted on 2010-01-06
2
Medium Priority
?
247 Views
Last Modified: 2013-12-19
Can I make these two subqueries into one?

select a.status_desc, a.dept_name, sku_count, fcr_count from
(select status_desc,
             dept_name,
             count(distinct fpo_no || style || colour) sku_count
      from agi_016a_t1
      group by status_desc, dept_name) a
left join
(select status_desc,
              dept_name,
              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;
0
Comment
Question by:orauser
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 375 total points
ID: 26191788
TRY TH0S
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

0
 

Author Closing Comment

by:orauser
ID: 31673541
Can adjust the temp table to contain distinct fpo/style/colour instead of doing it here
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question