troubleshooting Question

Sub Query

Avatar of JArndt42
JArndt42Flag for United States of America asked on
ProgrammingDB2
20 Comments1 Solution480 ViewsLast Modified:
I have the following query with a sub query that I am trying to make work. my first attempt at using a sub-query in a where statement. can anybody tell me why this does not work? I get an error that basically keywork ORDER not expected. Valid tokens: Union Except. (#-199)

SELECT DITRLR,COUNT(ORODR#) AS OCOUNT,SUM(CAST(ORESTR AS DOUBLE)) AS REV
FROM ORDER
INNER JOIN LOAD ON DIODR# = ORODR#
WHERE DITRLR IN
(SELECT DITRLR FROM ORDER INNER JOIN LOAD ON ORODR# = DIODR# WHERE ORPDAT BETWEEN 2007001 AND 2007365 AND DIDISP = '01'
AND ORCUST IN('AWISH','PASPRO','SAPAPO') GROUP BY DITRLR ORDER BY COUNT(ORODR#)  DESC FETCH FIRST 10 ROW ONLY)
AND ORPDAT BETWEEN 207001 AND 2007365 AND DIDISP = '01'
GROUP BY DITRLR
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros