mysql常用的查詢 MySQL常用查詢

2021-10-18 22:21:35 字數 1420 閱讀 3774

select from_unixtime(create_time, '%y-%m') as time,sum(sales_amount) sales_amount_sum from sales group by time

執行結果如下:

查詢每年的銷售額:

select from_unixtime(create_time, '%y') as time,sum(sales_amount) sales_amount_sum from sales group by time

執行結果如下:

注意:①在更換時間段的時候,只需要將from_unixtime的格式進行修改。(這裡的月銷售額與年銷售額相同只是因為建立的時候巧合了呀)

②這裡from_unixtime指的是將時間戳轉換為日期格式,(unix_timestamp是將日期格式轉化為時間戳)

③在使用date_ format的時候時間是具體的日期,其他與from_unixtime使用相同

④ date_format(date,format)

根據format字串格式化date值。下列修飾符可以被用在format字串中:

%m 月名字(january……december)

%w 星期名字(sunday……saturday)

%d 有英語字首的月份的日期(1st, 2nd, 3rd, 等等。)

%y 年, 數字, 4 位

%y 年, 數字, 2 位

%a 縮寫的星期名字(sun……sat)

%d 月份中的天數, 數字(00……31)

%e 月份中的天數, 數字(0……31)

%m 月, 數字(01……12)

%c 月, 數字(1……12)

%b 縮寫的月份名字(jan……dec)

%j 一年中的天數(001……366)

%h 小時(00……23)

%k 小時(0……23)

%h 小時(01……12)

%i 小時(01……12)

%l 小時(1……12)

%i 分鐘, 數字(00……59)

%r 時間,12 小時(hh:mm:ss [ap]m)

%t 時間,24 小時(hh:mm:ss)

%s 秒(00……59)

%s 秒(00……59)

%p am或pm

%w 乙個星期中的天數(0=sunday ……6=saturday )

%u 星期(0……52), 這裡星期天是星期的第一天

%u 星期(0……52), 這裡星期一是星期的第一天

%% 乙個文字「%」。

mysql常用的查詢 MySQL常用查詢

資料庫 1.查詢所有資料的大小 data length 資料大小 index length 索引大小 select concat round sum data length index length 1024 1024,2 mb as data from information schema.tab...

mysql 查詢 常用 mysql常用查詢

一.group concat函式,以指定的分割符合並列,與group by 一起用 例 selectgroup concat c.columnname separator group by 二.preparedstatement.return generated keys 得到剛剛插入記錄的id p...

常用的mysql查詢

查詢中文匹配 select cooperator name,business manager id from tbl cooperator where hex business manager id regexp e 4 9 0 9a f 查詢商戶名全是中文的資料。select cooperator...