码迷,mamicode.com
首页 > 数据库 > 详细

工作中的一些sql

时间:2014-12-04 14:08:00      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:ar   使用   sp   art   bs   ad   ef   工作   as   

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;


工作中的一些sql

标签:ar   使用   sp   art   bs   ad   ef   工作   as   

原文地址:http://my.oschina.net/u/565430/blog/352180

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!