开发者

strip 0 from all rows in single column MySQL

开发者 https://www.devze.com 2023-01-17 00:32 出处:网络
I want to TRIM(LEADING 0 FROM month) FROM table1 where table1 has column month with data form开发者_Go百科atted like so: 01, 02, 03

I want to TRIM(LEADING 0 FROM month) FROM table1

where table1 has column month with data form开发者_Go百科atted like so: 01, 02, 03

I would like to update the data so it is formatted as: 1, 2, 3, ...

Thanks!


Simplest way might be to just cast it to an int:

SELECT CAST(month as int) from table


From the MySQL docs:

mysql> SELECT MONTH('2008-02-03');
-> 2

So, if you only have the month (and not the rest of the date), you could use:

SELECT MONTH(CONCAT('2010-', month, '-', '01')) FROM table1;

Source: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month

0

精彩评论

暂无评论...
验证码 换一张
取 消