CREATETABLE orders_archived AS SELECT*FROM orders;
注意: 使用上述方式复制时,无法复制列属性,如主键等信息。
使用子查询插入数据
INSERTINTO orders_archived SELECT*FROM orders WHERE order_date <'2019-01-01'
Update
更新语法
UPDATE 语句基本语法为:
UPDATE [table_name] SET column_name = column_value, ...; WHERE [condition];
通常更新都需要有过滤条件。
UPDATE invoice SET payment_total = invoice_total *0.5, payment_date = due_date WHERE invoice_id =1;
更新语句使用子查询
UPDATE invoice SET payment_total = invoice_total *0.5, payment_date = due_date WHERE client_id = ( SELECT client_id FROM clients WHERE name ='Mywork' );