user829310
user829310

Reputation: 49

Oracle creating a table

How should we create a table which has a column as the average of the totals present in previous columns? For ex :Departments (depno,depname,noofempl,totalsal,avgsal)

here value in avgsal must be (totalsal/noofempl)

Upvotes: 0

Views: 125

Answers (1)

vc 74
vc 74

Reputation: 38179

If you are using Oracle 11 you might use virtual columns otherwise you can create a view that selects all your table columns and adds the average column

CREATE TABLE DEPARTMENTS
(
  DEPNO...
  DEPNAME...
  noofempl...
  totalsal...
);

CREATE VIEW VW_DEPARMENTS AS
SELECT DEPNO, DEPNAME, noofempl, totalsal, totalsal/noofempl as avgsal
FROM DEPARTMENTS;

Upvotes: 2

Related Questions