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`mysql
unix_timestamp(yesterDate)sql