繁体   English   中英

如何检查 MySQL 中从同一表的另一列派生的列元素的有效性?

[英]How can I check the validity of a column elements in MySQL that were derived from another column of the same table?

例如,如果我在一列中有 Project_ID = 123456 并且 Project_Name = R123456。 我想检查 Project_Name 是否在每个元素中都正确输入了前缀 R。 我可以使用什么查询?

select Project_ID,
       case when Project_Name = concat('R', Project_ID) 
            then 'ok' 
            else 'fail'
       end as result
from your_table

或仅获取不正确的:

select Project_ID
from your_table
where Project_Name <> concat('R', Project_ID)

暂无
暂无

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

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