我在ubuntu 16.04 lts上使用mysql服务器5.7,我想创建一个使用其他表中值的表。我在创建表时尝试使用select ... into,但是失败了。我创建了如下表。
mysql> create table BILLING_PRODUCTS_DETAILS
-> (
-> bill_Number int not null,
-> product_id int not null,
-> unit_Price decimal(8,2) not null,
-> purchase_Quantity int default 1,
-> purchase_Quantity_Price decimal(10,2) not null,
-> foreign key (bill_Number) references BILL_HEADER(bill_Number),
-> foreign key (product_Id) references PRODUCT_DETAILS(product_Id),
-> select product_Price into unit_Price from PRODUCTS_DETAILS where product_Id = PRODUCTS_DETAILS.product_Id,
-> select (purchase_Quantity * unit_Price) into purchase_Quantity_Price
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select product_Price into unit_Price from PRODUCTS_DETAILS where product_Id = PR' at line 10
答案 0 :(得分:0)
我认为您可以有一个更好的选择。您首先创建表,然后更新它。很简单。