mysql中常用sql语句
#1.分表后联表查询
select DATE_FORMAT(tmp.creatTime, ‘%Y-%m-%d’) as time,count(1),sum(tmp.coin) from
(select * from table_201910 UNION ALL select * from table_201911 UNION ALL select * from table_201912) tmp
where tmp.creatTime between ‘2019-11-01 00:00:00’ and ‘2019-12-04 23:59:59’ group by time order by time desc; – 统计每天签到人数
#2.复制和创建表
insert into table1 select * from table2; – 将表2数据复制到表1
create table table1 like table2; – 创建表1,表1结构和表2一样
#3.统计表中字段的绝对值
select sum(abs(change)) from record_round_coin where and userId=303535 and startTime
between ‘2019-12-04 00:00:00’ and ‘2019-12-04 23:59:59’; --查询表中特定字段的绝对值的和