[英]SQL to create a column from the value of another column
我有下表:
| id | name |
----------------------------------
| 1 | 236 SRTD - Something 1 |
----------------------------------
| 2 | 236 SRTD - Something 2 |
----------------------------------
| 3 | 236 SRTD - Something 3 |
----------------------------------
| 4 | 387 SRTD - Something 1 |
从该表我想构建另一个类似的视图,但看起来像如下:
| id | SRTD | name |
-------------------------------------------
| 1 | 236 | 236 SRTD - Something 1 |
-------------------------------------------
| 2 | 236 | 236 SRTD - Something 2 |
-------------------------------------------
| 3 | 236 | 236 SRTD - Something 3 |
-------------------------------------------
| 4 | 387 | 387 SRTD - Something 1 |
如何修改名称列,获取SRTD编号,然后创建包含该值的另一列。
对于SQL Server:
SELECT id, SRTD = SUBSTRING(name, 1, CHARINDEX(' ', name)), name
FROM dbo.table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.