如何在列名中使用LIKE [英] how to use LIKE with column name

查看:90
本文介绍了如何在列名中使用LIKE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常LIKE语句用于检查数据之类的模式.

Normally LIKE statement is used to check the pattern like data.

示例:

select * from table1 where name like 'ar%'

我的问题是在LIKE语句中使用表的一列.

My problem is to use one column of table with LIKE statement.

示例:

select * from table1, table2 where table1.x is like table2.y%

查询以上结果错误.如何在like查询中使用一列数据?

Query above results error . how to use one column data in like query?

推荐答案

您已经关闭.

LIKE运算符可用于字符串(CHAR,NVARCHAR等).因此您需要在字符串中包含'%'符号...

The LIKE operator works with strings (CHAR, NVARCHAR, etc). so you need to concattenate the '%' symbol to the string...


MS SQL Server:

MS SQL Server:

SELECT * FROM table1,table2 WHERE table1.x LIKE table2.y + '%'


但是,使用LIKE通常比其他操作慢.它是有用,强大,灵活的,但是具有性能方面的考虑.我会把这些留给另一个话题:)


Use of LIKE, however, is often slower than other operations. It's useful, powerful, flexible, but has performance considerations. I'll leave those for another topic though :)


我不使用MySQL,但这可能有效...

I don't use MySQL, but this may work...

SELECT * FROM table1,table2 WHERE table1.x LIKE CONCAT(table2.y, '%')

这篇关于如何在列名中使用LIKE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆