insert into select語句與select into from語句

ZHOU_VIP發表於2018-08-08

https://blog.csdn.net/weixin_39415084/article/details/76170240

https://www.cnblogs.com/duanxz/p/5208336.html

-----------------------------------------------------------------------------------------------------------------

現在我想把t_cgs_sm_user表的userid(值不為1)插入到t_cgs_sm_user_role_res表中,

其他欄位的值都一樣,為‘4’,'res_global',6,'全域性資源'

說明:帶引號的欄位是字串型別

INSERT INTO t_cgs_sm_user_role_res (userid,roleid,resid,restype,resname)

SELECT userid,'4','res_global',6,'全域性資源' FROM t_cgs_sm_user WHERE userid <> 1;

INSERT INTO t_cgs_sm_user_role_res
            (userid,
             roleid,
             resid,
             restype,
             resname)
SELECT
  userid,
  '4',
  'res_global',
  6,
  '全域性資源'
FROM t_cgs_sm_user
WHERE userid <> 1;

 

 

相關文章