954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VIEW in SQL

Can anyone see anything wrong with this statement?

CREATE OR REPLACE VIEW V_DEPT_AMOUNT AS       
	      SELECT DEPTNO AS DNO, DNAME AS DNAME, MAX(AMOUNT) AS  MAX_AMOUNT, 
              AVG(AMOUNT) AS AVG_AMOUNT, MIN(AMOUNT) AS MIN_AMOUNT, 
              SUM(AMOUNT) AS  TOTAL_AMOUNT FROM DEPT D, EMP E, PURCHASE P
              WHERE D.DEPTNO = E.DEPTNO
	      GROUP BY DNAME, DEPTNO;


It is meant to list names and numbers of all company departments together with the maximum, minimum, average and total amount contributed by each department.


The error I am getting is that "column ambiguously defined"

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

You should define alias to column name also. Which column belongs to which table. It will solve your error. For eg SELECT D.DEPTNO AS DNO, D.DNAME AS DNAME.. Like wise..

ruhi
Light Poster
25 posts since Jun 2007
Reputation Points: 23
Solved Threads: 1
 

Thanks, buddy..

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

You are welcome..Mark it solved na:)

ruhi
Light Poster
25 posts since Jun 2007
Reputation Points: 23
Solved Threads: 1
 

It isn't solved yet...

1. You have a 3rd table, yet there is no reference in your Where clause.
(This may generate more records than you're expecting.)

2. Your error is being generated by your Group by.
You have a DEPTNO, but do NOT specify from which table.
(ie. Add aliases to all of the columns.)

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You