英文:
Need to select people whose name starts with "M" or the second from the end letter of the last name is "i"? The column has persons name, surname
问题
我在SQL中的表中有一列包含人的名字和姓氏,例如"Mike Baldwin"、"Sara Larson"等,我需要输出所有名字以"M"开头或姓氏倒数第二个字母是"i"的人。我应该如何在脚本文件中编写它?
所以我制作了这个脚本:
SELECT * FROM your_table WHERE CLIENT LIKE 'M%' OR CLIENT LIKE '%i_'
但这个脚本输出了名字的倒数第二个字母也是"i"的人。
英文:
My table in SQL has a column with persons name and surname like "Mike Baldwin", "Sara Larson" etc. and need to output all the persons whose name starts with "M" or surnames second last letter is "i". How do I write it in script file?
So I made this script :
SELECT * WHERE CLIENT LIKE 'M%' OR CLIENT LIKE '%i_'
but this script outputs persons whose second last letter of the name is also "i".
答案1
得分: 0
根据我理解;name
和 surname
是根据您的解释两个不同的列;
select *
from table_name
where name like 'M%' OR surname like '%i_';
应该可以工作。
请在上面的查询中替换实际的列名
============================================================
更新:
根据解释;
有一个单独的列 client
,其中存储了通过空格分隔的 name
和 surname
。
select *
from table_name
where SUBSTR(client, 1, 1) = 'M'
OR SUBSTR(client, INSTR(client, ' ', -1) - 1, 1) = 'i';
英文:
As I understand; name
and surname
are two different columns based on your explanation;
select *
from table_name
where name like'M%' OR surname like '%i_';
Shall work.
Please replace the actual column names in above query
============================================================
Update :
Based on explanation;
There a single column client
which stores name
and surname
seperated by a space
select *
from table_name
where SUBSTR(client, 1, 1) = 'M'
OR SUBSTR(client, INSTR(client, ' ', -1) - 1, 1) = 'i';
答案2
得分: 0
只返回翻译好的部分:
"Thinking use some Regex here. Something like but I don't know how regex works in oracle?
SELECT *
FROM table_name
WHERE CLIENT LIKE 'M%' OR
REGEX_LIKE (CLIENT , '^[a-zA-Z]+\s.[i]+[a-zA-Z]*$')
Updated the regex!"
英文:
Thinking use some Regex here. Something like but I don't know how regex works in oracle?
SELECT *
FROM table_name
WHERE CLIENT LIKE 'M%' OR
REGEX_LIKE (CLIENT , '^[a-zA-Z]+\s.[i]+[a-zA-Z]*$')
Updated the regex!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论