sql - 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?
解决方案
如果您使用 mysql 为什么不使用比子字符串更精确的提取?!
选择摘录(来自“2017-06-15”的年份)
推荐阅读
- wordpress - 常量插件 URL
- python - 为什么在孩子的init方法中使用Python super?
- flutter - Flutter 视频播放器 Android TV
- javascript - 为什么我可以在 Node.js 命令行中创建文件,但不能在程序中创建文件?
- javascript - 简单的纯 JavaScript 图像滑块
- c - C libgit2 - 按提交列出文件
- laravel - Laravel Bootstrap 导航栏折叠
- java - Android Studio:在导入 Eclipse 项目期间找不到 com.android.tools.build:gradle:3.6.2
- react-native - 在 Cloudinary 上使用 axios 上传 React-Native imagePicker
- r - 高斯 GAM(MGCV 包)中因变量的方差估计?