您的位置:首页 > 博客中心 > 数据库 >

工作中的一些sql

时间:2022-03-14 03:22

1、exists/not exsists

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);

2、插入批量结果集、mysql日期函数使用

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
);

3、关联更新

update 
  t_user a ,t_guizu_privilege b 
set 
  a.fk_special_effects = b.fk_special_effects 
where 
  a.user_level = b.level;


热门排行

今日推荐

热门手游