简体   繁体   English

SQL结合在哪里和选择

[英]SQL Combining Where and Select

I have a string of data, House Electricity - 1234 , which i have stored in an SQL database. 我有一个数据字符串, House Electricity - 1234 ,它存储在SQL数据库中。

I am attempting to restrict the string down to the four digit number code at the end, but when the data is put into the database it needs to have the descriptive terms first. 我试图将字符串最后限制为四位数的数字代码,但是当数据放入数据库时​​,它首先需要具有描述性术语。

The environment I am working in lets me run SQL queries , however there is a catch. 我正在使用的环境允许我运行SQL查询 ,但是有一个问题。

It must begin with SELECT Nominal_Code FROM Housing WHERE 它必须以SELECT Nominal_Code FROM Housing WHERE开头

I can't change the order of these. 我无法更改这些顺序。

I have tried putting in a RIGHT ('House Electricity - 1234', 4) in afterwards, but it doesn't seem to do anything. 我曾尝试在之后放一个RIGHT(“ House Electricity-1234”,4),但它似乎无能为力。

Is there any solution to this? 有什么解决办法吗?

Edit for clarity. 编辑清楚。

The Column is called Nominal_Code 该列称为Nominal_Code

The Table is called Housing 该表称为房屋

The solution must start with SELECT Nominal_Code FROM Housing WHERE - as the software I am using (Docuware) requires it in that exact format to begin with. 解决方案必须以“ SELECT Nominal_Code FROM Housing WHERE -因为我正在使用的软件(Docuware)要求以确切的格式开始。

The goal is to get House Electricity - 1234 to replace itself with 1234. 目标是让House Electricity - 1234用1234代替自己。

Too long for a comment... 评论太久了...

Seems fine to me: 对我来说似乎很好:

SELECT 'a123', RIGHT('a123',3);
+------+-----------------+
| a123 | RIGHT('a123',3) |
+------+-----------------+
| a123 | 123             |
+------+-----------------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM