How should we create a table which has a column as开发者_StackOverflow社区 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)
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;
精彩评论