Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15421
  • 博文数量: 4
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-21 12:54
文章分类
文章存档

2014年(1)

2013年(3)

我的朋友

分类: Mysql/postgreSQL

2013-07-10 09:32:56

原文地址:一表多连的sql语句 作者:xyaxlz


点击(此处)折叠或打开

  1. CREATE TABLE if not exists tmp_c5online_table(
  2.         `role_name` VARCHAR(255) NOT NULL
  3. );

  4. insert into tmp_c5online_table
  5. SELECT distinct(r.account)
  6. FROM
  7.         hdzm_gamedb.RolesTable r
  8.         ,hdzm_log.role_duration_log as l
  9.         ,hdzm_log.role_duration_log as l0
  10.         ,hdzm_log.role_duration_log as l1
  11.         ,hdzm_log.role_duration_log as l2
  12.         ,hdzm_log.role_duration_log as l3
  13.         ,hdzm_log.role_duration_log as l4
  14. where
  15.         DATEDIFF(now(), l0.online_date) = 0 and l0.role_name = l.role_name
  16.         and DATEDIFF(now(), l1.online_date) = 1 and l1.role_id = l.role_id
  17.         and DATEDIFF(now(), l2.online_date) = 2 and l2.role_id = l.role_id
  18.         and DATEDIFF(now(), l3.online_date) = 3 and l3.role_id = l.role_id
  19.         and DATEDIFF(now(), l4.online_date) = 4 and l4.role_id = l.role_id
  20.         and r.role_id = l.role_id
  21. ;

  22. insert into xxx_gamedb.AccountsAward (`account`, `awards`, `award_time`, `award_type`)
  23. select role_name, "3300012:10;5040000:5;5040002:1", now(), 1001
  24. from tmp_c5online_table c2
  25. where
  26. role_name not in (
  27.         select c5.role_name from tmp_c5online_table c5, xxx_gamedb.AccountsAward a
  28.         where
  29.         c5.role_name = a.account
  30.         and DATEDIFF( now(), a.award_time) <= 4
  31.         and a.award_type = 1001
  32. )
  33. ;

  34. drop table tmp_c5online_table;

阅读(1052) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Linux Nginx FastDFS模块安装 nginx与fastDFS整合

给主人留下些什么吧!~~