MySQL部分sql記錄

2021-10-05 08:32:17 字數 1653 閱讀 3203

url: jdbc:mysql:
allowmultiqueries=true為mybatis的xml檔案可以批量修改

select

date_format(a.created_time,'%m') months,

count(a.id) counts,

sum(timestampdiff(second,a.created_time,a.updated_time)) timecounts

from hm_service_detail a, hm_online_chat b

where a.health_service = b.id and b.to_user = #

and a.created_time #

group by months;

1.sum(timestampdiff(second,a.created_time,a.updated_time)) timecounts統計時間差

2.#與jdbctype=「date」、jdbctype="timestamp"的區別就是date直到年月日,timestamp到時分秒,一般帶時間查詢需要注意

select

id,create_id createid,

created_time createdtime,

type,

module_name modulename,

comment

from hm_log

and date_format(created_time, '%y-%m-%d') = date_format(#,'%y-%m-%d')

and type = #

order by created_time desc

mysql欄位型別為blob時中文亂碼問題,對映實體時typehandler對應工具類basetypehandler,這樣查詢後的資料中文就可以正常顯示了

public class myblobtypehandler extends basetypehandler catch (unsupportedencodingexception e) 

ps.setbinarystream(i, bis, parameter.length());

}@override

public string getnullableresult(resultset rs, string columnname)

throws sqlexception

try catch (unsupportedencodingexception e)

}@override

public string getnullableresult(callablestatement cs, int columnindex)

throws sqlexception

try catch (unsupportedencodingexception e)

}@override

public string getnullableresult(resultset rs, int columnindex)

throws sqlexception

}

DB 部分MySQL操作記錄

工作中涉及到部分統計工作,恰好把之前的有些sql再熟悉回顧一下。一.涉及到時間統計部分 求時間差 select timestampdiff day,select date create date from account where id 37 select curdate as 試用時間 sele...

Mysql的部分常用SQL語句

管理 查詢 1.查詢資料庫中,包含有資料記錄的表名 select table name from information schema.tables where table schema 資料庫名稱 and table rows 0 2.查詢當前日期時間前三天資料 select from 表名 wh...

mysql 開啟sql日誌,記錄所有sql

我使用的mysql版本為 5.7.11 win7環境 mysql 預設沒有開啟sql日誌。下面步驟開啟sql日誌 找到my.ini檔案,預設是在 c programdata mysql mysql server 5.7 先備份一下my.ini。以免出錯改不回來,開啟my.ini,找到並修改為 日誌輸...