阅读247 返回首页    go 阿里云 go 技术社区[云栖]


mysql 临时表 创建和插入

mysql 2张表插入到临时表里
一个项目用到多张表数据合计查询
by 夜色紫宸风

DROP TABLE IF EXISTS tmp_table;
CREATE TEMPORARY TABLE tmp_table SELECT appid,uid FROM `sz_app_credit_log_201111`;
INSERT INTO tmp_table  SELECT appid,uid FROM `sz_app_credit_log`;
SELECT * FROM tmp_table;


具体例子


DROP TABLE IF EXISTS tmp_table;
CREATE TEMPORARY TABLE tmp_table SELECT appid,uid,sum(ovalue) as s FROM `sz_app_credit_log_201111` l where l.appid='7' and l.operate='add' and l.dateline>=UNIX_TIMESTAMP('2011-11-01') and l.dateline<UNIX_TIMESTAMP('2011-12-01')  GROUP BY uid;
INSERT INTO tmp_table  SELECT appid,uid,sum(ovalue) as s FROM `sz_app_credit_log` l where l.appid='7' and l.operate='add' and l.dateline>=UNIX_TIMESTAMP('2011-11-01') and l.dateline<UNIX_TIMESTAMP('2011-12-01') GROUP BY uid;
SELECT t.appid,t.uid,m.tel,sum(t.s) as s FROM tmp_table t left join sz_ucenter_members m on t.uid=m.uid group by uid order by sum(t.s) desc limit 0,500;


最后更新:2017-04-02 06:52:12

  上一篇:go 国家/地区 语言缩写代码 查询备用
  下一篇:go 天气预报,MYSQL之JDBC查询模块实现(代码)和简易插入模块实现(代码)以及PREPAREDSTATEMENT插入模块实现(代码)