1. 程式人生 > 其它 >ubuntu20.04下mysql安裝

ubuntu20.04下mysql安裝

//查詢一週
格式:select * from 表名稱 where date_sub(curdate(), interval 6 day) <= date(表內時間欄位);
語句:select * from garbage_collect  where date_sub(curdate(), interval 6 day) <= date(collection_time);

//查詢一個月
 格式:select * from 表名稱 where date_sub(curdate(), interval 1 month) <= date(表內時間欄位);
 語句:select * from garbage_collect  where date_sub(curdate(),  interval 1 month) <= date(collection_time);

//查詢近半年 格式:select * from 表名稱 where date_sub(curdate(), interval 6 month) <= date(表內時間欄位); 語句:select * from garbage_collect where date_sub(curdate(), interval 6 month) <= date(collection_time);
//查詢2020年的資料:
格式:select * from 表名稱 where year(表名稱.表字段)="某年" 
語句:select * from garbage_collect where year(garbage_collect.collection_time)="2020" 
//
查詢9月份的資料: 格式:select * from 表名稱 where year(表名稱.表字段)="某月" 語句:select * from garbage_collect where month(garbage_collect.collection_time)="09" //查詢時期是08的資料: 格式:select * from 表名稱 where year(表名稱.表字段)="某日" 語句:select * from garbage_collect where day(garbage_collect.collection_time)="08" //查詢2020年03月份的資料: select * from garbage_collect where year(garbage_collect.collection_time)="2020" and month(garbage_collect.collection_time)="03" //
查詢2020年03月06日的資料: select * from garbage_collect where year(garbage_collect.collection_time)="2020" and month(garbage_collect.collection_time)="03" and day(garbage_collect.collection_time)="06";
格式:select * from 表名稱 where 表字段 between "開始時間" and "結束時間";
語句:select * from garbage_collect where collection_time  between "2020-02-01" and "2020-03-31";

//查詢指定時間段資料(開始時間-結束時間)包含結束時間
語句:select * from garbage_collect where  collection_time  between "2020-03-17" and date_add("2020-03-17",interval 1 day)