首页 > 解决方案 > SQL extract substring from text column

问题描述

I have the following table and I want to extract the year from the second column (as show in the second table).

Points | Year
______________
100    | 04/07/2014 - 06/07/2014
200    | 22/06/2017 - 24/06/2017
300    | 30/06/2015 - 02/07/2015

Points | Year
______________
100    | 2014
200    | 2017
300    | 2015

My approach is using the substring statement but doesn't seem to work.

SELECT Points, SUBSTRING(Year, 5, 4) as Year
FROM tabel1; 

Any ideas what I might be doing wrong?

标签: sqlsqlitesubstring

解决方案


如果您使用 mysql 为什么不使用比子字符串更精确的提取?!

选择摘录(来自“2017-06-15”的年份)


推荐阅读