1. 程式人生 > >MySQL字元varchar轉換為int、date

MySQL字元varchar轉換為int、date

1.varchar轉int

函式:cast
用法:cast(欄位 as SIGNED INTEGER)
或者cast(欄位 as UNSIGNED INTEGER))

2.varchar轉date

函式:str_to_date(欄位,字串格式)
用法:select str_to_date(欄位,'%Y-%m-%d') from tablea limit 100;

根據日期進行選取

選取日期大於2019年的所有欄位

select * from tablea where str_to_date(tablea.日期,'%Y-%m-%d')>'2019-00-00';