SQL insert into select 語句

遇到權限數據變動的須要批量到別的平臺, 在175平臺添加一個權限須要, 批量到別的現有平臺, 之後的建站, 會把sql放到自動建站裏面;html

權限的 insert into select web

  表一: `ouser`.`u_function`   權限表sql

  表二: misc.gxej_company    平臺表dom

  sql:spa

  

    
INSERT INTO `ouser`.`u_function` (
    `code`,
    `parent_code`,
    `product_type`,
    `type`,
    `domain`,
    `path`,
    `name`,
    `desc_`,
    `level`,
    `target`,
    `icon`,
    `sort_value`,
    `is_available`,
    `is_deleted`,
    `version_no`,
    `create_userid`,
    `create_username`,
    `create_userip`,
    `create_usermac`,
    `create_time_db`,
    `server_ip`,
    `update_userid`,
    `update_username`,
    `update_userip`,
    `update_usermac`,
    `update_time_db`,
    `client_versionno`,
    `company_id`,
    `platform_id`
) SELECT
    '307788',
    '3077',
    NULL,
    '1',
    '/back-finance-web',
    '/#/stmMerchantSoStatementListOld/2',
    '商家銷售結算單舊',
    NULL,
    '2',
    NULL,
    NULL,
    '99',
    NULL,
    '0',
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,

    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    c.id,
    '2'
FROM
    misc.gxej_company c where c.id != 175;  #去掉175平臺

  

角色的insert into select  code

  涉及到左鏈接:orm

    insert into ... select ... where ... join語法 例子server

insert into T2(c1, c2, c3)
select
t1.c1,
t1.c2,
t1.c3
from T1 t1
where
t1.c2 = 'y'
left join T3 t3 on t1.c1 = t3.c1
left join T4 t4 on t1.c1 = t4.c1;

  

  權限關聯表 : u_role_functionhtm

  角色表: u_role blog

  權限表:  u_function 

  注意: on 條件生產臨時表

INSERT INTO `ouser`.`u_role_function` (
    
    `role_id`,
    `function_id`,
    `is_available`,
    `is_deleted`,
    `version_no`,
    `create_userid`,
    `create_username`,
    `create_userip`,
    `create_usermac`,
    `create_time`,
    `create_time_db`,
    `server_ip`,
    `update_userid`,
    `update_username`,
    `update_userip`,
    `update_usermac`,
    `update_time_db`,
    `client_versionno`,
    `company_id`
)
SELECT
        r.id,
        f.id,
        NULL,
        '0',
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        r.company_id
    FROM ouser.u_role r LEFT JOIN ouser.u_function f on r.company_id = f.company_id  where r.code ='merchant_role_code_enter_type_1'  and f.code LIKE '%307788%' 
相關文章
相關標籤/搜索