一、exists/not exsistsmysql
select b.yid yid, b.ytid ytid from t_user a, t_yidytidmapping b where a.fk_origin_user = b.ytid and not exists (select * from t_user d where b.yid = d.fk_origin_user);
二、插入批量結果集、mysql日期函數使用sql
insert into t_pack_item(gid, free_count, buy_count, start_time, end_time, user_id) ( select (b.g_type * 100000 + b.business_id) gid, 1 free_count, 0 buy_count, now() start_time, (select date_add(now(), interval 100 * 365 day)) end_time, a.fk_origin_user user_id from t_user a, t_shop_product b where a.fk_origin_user = 301787931 and a.user_level > 0 and b.id in(3,4,5,6,7) order by a.fk_origin_user );
三、關聯更新app
update t_user a ,t_guizu_privilege b set a.fk_special_effects = b.fk_special_effects where a.user_level = b.level;