sql - Adding a computed column in mysql -


i'm trying add column called 'price' order_details table. want calculate price different prices of products other tables.

alter table order_detail add column price decimal(5,2)   (case (order_detail.item_id,         item.item_id,         bagel.item_id,         bagelfilling.item_id,         item.price,         bagelfilling.price,        order_detail.quantity,        order_detail.discount,        drink_sizes.price,        drink.item_id)          when (order_detail.item_id = item.item_id) , (item.item_id = bagel.item_id) , (bagel.item_id = bagelfilling.item_id)             ((item.price + bagelfilling.price)*order_detail.quantity)-order_detail.discount           when (order_detail.item_id = item.item_id) , (item.item_id = drink.item_id)             ((item.price + drink_sizes.price)*order_detail.quantity)-order_detail.discount          when (order_detail.item_id = item.item_id) , (item.item_id = bagel.item_id)               (item.price*order_detail.quantity)-order_detail.discount          when (order_detail.item_id = item.item_id) , (item.item_id = drink.item_id)             (item.price*order_detail.quantity)-order_detail.discount            else 0.00                end) 

i keep running error:

error code: 1241. operand should contain 1 column(s).

how fix issue? need price calculated either when table created or when data added.

  1. you cannot reference fields other tables in expression of calculated field, since no subqueries allowed. so, if fix syntax error you, not work. task seems require trigger, or stored procedure, or view.

  2. even though can have expression after case keyword, listing column names not valid expression, since not return single value.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -