mysql 多条语句合并查询
select count(*) from matches where StartTime > 1519315200 and endtime < 1519401600 and matchtype = 1 union all select count(*) from matches where StartTime > 1519315200 and endtime < 1519401600 and matchtype = 2 union all select count(*) from matches where StartTime > 1519315200 and endtime < 1519401600 and matchtype = 3;
union不允许重复的值 union all 允许重复值
select distinct name from table 查询去除重复键值
1.查看数据库编码格式 1 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 1 mysql> show create table <表名>; 3.创建数据库时指定数据库的字符集 mysql>create database <数据库名> character set utf8; 4.创建数据表时指定数据表的编码格式 create table tb_books ( name varchar(45) not null, price double not null, bookCount int not null, author varchar(45) not null ) default charset = utf8; 5.修改数据库的编码格式 mysql>alter database <数据库名> character set utf8; 6.修改数据表格编码格式 mysql>alter table <表名> character set utf8; 7.修改字段编码格式 mysql>alter table <表名> change <字段名> <字段名> <类型> character set utf8; mysql>alter table user change username username varchar(20) character set utf8 not null; 8.添加外键 mysql>alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid); mysql>alter table <表名> add constraint <外键名> foreign key<字段名> REFERENCES <外表表名><字段名>; 9.删除外键 mysql>alter table tb_people drop foreign key fk_1; mysql>alter table <表名> drop foreign key <外键名>;
自动增加列号 select (@i:=@i+1) as ord_num,time from log,(select @i:=0)b limit 10;
增加自定义列和内容 select "0~24" as "时间段",count(1) from log
from_unixtime将时间戳格式化
SELECT DISTINCT userid1 from ningxia_logic.video where from_unixtime(Time) > '2017-03-24 16:40:00' and from_unixtime(Time) < '2017-03-24 18:05:00'
unix_timestamp 将格式化,转成时间戳
yesterDate=`date +%Y%m%d -d -1day`
curDate=`date +%Y%m%d`
unix_timestamp(yesterDate)
posted on 2018-02-24 10:54 zyz913614263 阅读(1721) 评论(0) 编辑 收藏 举报