Mysql常用的SQL

又一次忘了,写博客里吧

Posted on 2018-03-07 17:30:00 in Mysql   阅读(4180) Last updated on 2019-12-11 15:28:14

更新
update b, (select * from a) as ali set b.name = ali.name where b.a_id = ali.id;

插入
INSERT INTO ucenter_owner_voucher_template(`owner_id`, `type`, `create_pin`, `update_pin`) SELECT owner_id, 1, '[系统]', '[系统]' FROM ucenter_owner where owner_id not in (select owner_id from ucenter_owner_voucher_template where `type` = 1);

统计每个表的数据大小
select table_name, round((data_length+index_length)/1024/1024,2), concat(round((data_length+index_length)/1024/1024,2),'MB') from information_schema.tables where table_schema='neuron_basic' group by table_name;

字符截取
select substring_index(name_path, ",", 1), substring_index(substring_index(name_path, ",", -2), ",", 1), substring_index(substring_index(name_path, ",", -1), ",", 1)from common_region;