mysql 查询出数据作为变量插入

SELECT
    @zc_id := t3.ZC_ID
FROM
    表1 t1,
    表2 t2,
    表3 t3
WHERE
    t1.ZS_ID = t2.ZS_ID
AND t2.ZS_ID = t3.ZS_ID
AND t2.ZD_ID = t3.ZD_ID
AND t1.SN_ID = 28
AND t2.ZN_Name = '美国';  

delete from 表4 where zc_id = @zc_id;


INSERT INTO 表4 (zc_id,begincode,endcode) VALUES
(@zc_id,'50500','50500'),
(@zc_id,'50501','50501');
 

你可能感兴趣的:(test)