So let's say we have a table called Prices with columns Price1 and Price2, and I want to create a View called Totals with a column called PriceTotals that adds Price1 and Price2 on the table, and a second column called PriceCut that simply divides PriceTotals on the view by 2:

create view `Totals` as
   select
     `Price1` + `Price2` as `PriceTotals`,
     /**Put column definition here that divides PriceTotals by 2**/ as `PriceCut`       
   from `Prices`;

How do I go about that?

1

There are 1 answers

2
Joe Stefanelli On BEST ANSWER

Can't you just do this?

CREATE VIEW Totals AS
    SELECT Price1 + Price2 AS PriceTotals,
           (Price1 + Price2)/2 AS PriceCut
        FROM Prices;