我在 MYSql 数据库中有一个查询。我有一个表 order_det
,表的列 remarks_desc
包含如下条目:
表结构:
Table: order_det
Columns: rec_id, remarks_desc
order_det 表中的示例记录
rec_id remarks_desc
_________________________________________________________
1 a specific PROGRAMMING problem
2 A software Algorithm
3 software tools commonly USED by programmers
4 Practical, answerable problems that are unique to the programming profession
5 then you’re in the right place to ask your question
6 to see if your QUESTION has been asked BEFORE
我的要求我想只选择包含更多存储在所有大写字母中的单词的记录。从上面6条记录中,我只想选择下面1,3,6条记录:
rec_id remarks_desc
__________________________________________________
1 a specific PROGRAMMING problem (it contains one all uppercase word PROGRAMMING)
3 software tools commonly USED by programmers (it contains one all uppercase word USED)
6 to see if your QUESTION has been asked BEFORE (it contains two all uppercase words QUESTION and BEFORE)
我尝试使用 LIKE, REGEXP 将其存档,但得到的结果不正确。 请帮助我获得正确的结果。
最佳答案
尝试:
SELECT rec_id, remarks_desc FROM order_det WHERE remarks_desc REGEXP '(^|[[:blank:]])[[:upper:]][[:upper:]]+([[:blank:]]|$)'
我假设您要排除单字母大写的单词。如果您想排除字符串开头的大写单词,则需要调整正则表达式。
确保您的表格排序规则区分大小写(_cs 而非 _ci)
我使用了来自 http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp 的信息
但是,如果您不得不使用正则表达式从数据库中提取数据,则值得考虑是否可以改进您的数据库设计。 如果您需要数据库的良好性能,这一点尤为重要。
关于mysql - 选择包含一个或多个完全大写的单词的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13119958/