【问题标题】:Insert multiple rows into a table在表格中插入多行
【发布时间】:2013-02-15 00:42:42
【问题描述】:

我想要做的是创建一个存储过程,它将从另一个表插入到一个表中,但是插入的行数将根据“篮子”表中 c_id 实例的数量而有所不同。

CREATE PROCEDURE `proc_Transaction` ()
BEGIN

INSERT INTO transactions 
    (t_id, p_id, u_id, price, qty, total)  status, when_sold) 
VALUES 
    (@t_id, @p_id, @c_id, @Price, @Qty, @total, );
    SELECT p_id, c_id, qty FROM basket;


END

我想从我的“篮子”表中为每个等于指定值的 c_id 实例插入到上面的“事务”表中。所以可能只插入一行或多行。对于插入的每一行,t_id 将保持不变。

【问题讨论】:

    标签: mysql stored-procedures


    【解决方案1】:

    这是你想要的吗?

    INSERT INTO transactions (t_id, p_id, u_id, price, qty, total)
        SELECT @t_id, p_id, c_id, qty, @total FROM basket;
    

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-23
      • 1970-01-01
      • 2022-11-18
      相关资源
      最近更新 更多