求教or的用法
请高手帮看看,我想排除“树根”和“树瘤”的记录条,但结果老不对,即树瘤的记录老是出再,错出哪了?
id name
001 栎木树根
001 栎木树瘤
001 栎木原木
SELECT ID,NAME FROM TEMP
WHERE ID='001'
AND (NAME NOT LIKE '%树根%' OR NAME NOT LIKE '%树瘤%')
[解决办法]
SELECT ID,NAME FROM TEMP
WHERE ID='001'
AND (NAME NOT LIKE '%树根%' AND NAME NOT LIKE '%树瘤%')
[解决办法]
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-14 12:54:00
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
--Jun 10 2013 20:09:10
--Copyright (c) Microsoft Corporation
--Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] varchar(3),[name] varchar(8))
insert [huang]
select '001','栎木树根' union all
select '001','栎木树瘤' union all
select '001','栎木原木'
--------------开始查询--------------------------
select * from [huang]
WHERE name NOT LIKE '%树瘤%' and name NOT LIKE '%树根%'
----------------结果----------------------------
/*
id name
---- --------
001 栎木原木
*/
SELECT * FROM TB WHERE NAME NOT LIKE '%树[根瘤]%'
SELECT ID,NAME FROM TEMP
WHERE ID='001'
AND (NAME NOT LIKE '%树根%' and NAME NOT LIKE '%树瘤%')