Link to home
Start Free TrialLog in
Avatar of RenitlahHelp
RenitlahHelpFlag for United States of America

asked on

Oracle SQL Question

I am receiving an invalid identifier for "CUSTBAL"... any ideas why?  Thanks!
SELECT CUSTOMER_NUM, CUSTOMER_NAME, SUM(BALANCE) AS CUSTBAL, REP.REP_NUM FROM CUSTOMER, REP WHERE CUSTOMER.REP_NUM=REP.REP_NUM AND (CUSTBAL>10000) GROUP BY CUSTOMER_NUM;

Open in new window

Avatar of yousaftahir
yousaftahir

It is not working becuase CUSTBAL column does not exist in either cusomter and rep. you need to use derived table for the solution as :

select CUSTOMER_NUM, CUSTOMER_NAME,  CUSTBAL, REP.REP_NUM from (
 SELECT CUSTOMER_NUM, CUSTOMER_NAME, SUM(BALANCE) AS CUSTBAL, REP.REP_NUM FROM CUSTOMER, REP
WHERE CUSTOMER.REP_NUM=REP.REP_NUM  GROUP BY CUSTOMER_NUM)
as tblderived where (CUSTBAL>10000)
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RenitlahHelp

ASKER

Excellent!