SQL 查询近似值
SQL IN query for approximate values
我正在尝试使用 SQL IN
函数从 table 检索信息。
我正在使用以下 select
,我的逻辑是搜索包含缩写 'SMS' 的字段。但是,查询仅检索 'Other Services'
的值
如何只查询字段中的部分值?
这是我正在使用的 select 函数:
select product_id ,product_name
from product
where product_name
IN ('Other Services','%SMS%')
我正在使用 PL/SQL 开发人员。目前我只对适用于此 DBMS 的解决方案感兴趣。
尝试:
SELECT product_id,
product_name
FROM product
WHERE product_name = 'Other Services'
OR product_name LIKE '%SMS%';
请注意,某些数据库服务器对 LIKE 运算符区分大小写。
通配符承租人"LIKE "不能在"IN"运算符中使用。你使用它的方式。
要获得预期的输出,您可以使用类似这样的方法。
SELECTproduct_id,
product_name
从产品
其中 product_name = 'Other Services'
或 product_name LIKE '%SMS%'
或
SELECTproduct_id,
product_name
从产品
其中 product_name = 'Other Services'
联盟
SELECTproduct_id,
product_name
从产品
WHERE product_name LIKE '%SMS%'
IN
运算符不接受带有通配符的值。而是使用 LIKE
运算符。
select product_id ,product_name
from product
where product_name='Other Services'
OR product_name LIKE '%SMS%'
我正在尝试使用 SQL IN
函数从 table 检索信息。
我正在使用以下 select
,我的逻辑是搜索包含缩写 'SMS' 的字段。但是,查询仅检索 'Other Services'
如何只查询字段中的部分值?
这是我正在使用的 select 函数:
select product_id ,product_name
from product
where product_name
IN ('Other Services','%SMS%')
我正在使用 PL/SQL 开发人员。目前我只对适用于此 DBMS 的解决方案感兴趣。
尝试:
SELECT product_id,
product_name
FROM product
WHERE product_name = 'Other Services'
OR product_name LIKE '%SMS%';
请注意,某些数据库服务器对 LIKE 运算符区分大小写。
通配符承租人"LIKE "不能在"IN"运算符中使用。你使用它的方式。
要获得预期的输出,您可以使用类似这样的方法。
SELECTproduct_id, product_name 从产品 其中 product_name = 'Other Services' 或 product_name LIKE '%SMS%'
或
SELECTproduct_id, product_name 从产品 其中 product_name = 'Other Services' 联盟
SELECTproduct_id, product_name 从产品 WHERE product_name LIKE '%SMS%'
IN
运算符不接受带有通配符的值。而是使用 LIKE
运算符。
select product_id ,product_name
from product
where product_name='Other Services'
OR product_name LIKE '%SMS%'