开发者

Oracle creating a table

开发者 https://www.devze.com 2023-04-04 00:32 出处:网络
How should we create a table which has a column as开发者_StackOverflow社区 the average of the totals present in previous columns?

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消