Depends on the pn of the database provider ... For example, in SQL Server, you can create a column that calculates its value based on the values ββof other columns on the same row. they are called computed columns, and you do it like this:
Create Table MyTable ( colA Integer, colB Integer, colC Intgeer, SumABC As colA + colB + colC )
Typically, just enter the name of the column you want, the word βlike,β and the formula or equation to enhance the meaning. This approach does not use aditonal storage, it calculates the value every time someone executes the selected aganist, so the profile of the table remains narrower and you get better performance. The only downsode is that you cannot put an index in a computed column. (although there is a flag on the SQL server that allows you to specify in the database that it should keep the value whenever it is created or updated ... In this case, it can be indexed)
In your example, however, you are accessing data from multiple rows in another table. To do this, you need a trigger, as suggested by other respondents.
source share