SELECT * FROM TB WHERE 条款 IN(1,2,6,4,5) AND 供应商 NOT IN(2,12) UNION ALL SELECT * FROM TB WHERE 条款=3 AND 供应商 IN(2,12)???
/***********************************************--> 测试数据:[表A] --> 测试时间:2009-08-13 09:15:48 --> 我的淘宝:<<戒色坊>> http://shop36766744.taobao.com/***********************************************/if object_id('[表A]') is not null drop table [表A] create table [表A]([供应商] int,[条款] int) insert [表A] select 2,3 union all select 12,3 union all select 53,1 union all select 45,4 union all select 45,3 union all select 564,3 select [供应商],[条款] from ( select [供应商],[条款],flag=case when [供应商]=2 or [供应商]=12 then 1 else [条款] end from [表A] ) t where flag<>3 /* 供应商 条款 flag ----------- ----------- ----------- 2 3 1 12 3 1 53 1 1 45 4 4(4 行受影响)*/ drop table [表A]
select * from a where 条款 in(1,2,6,4,5) --不包括3的条款,供应商2,12不包括3的条款 union all select * from a where 条款=3 and 供应商 in(2,12) --加上供应商为2,12中条款为3的记录或者如下: select * from a where 条款>3 union all select * from a where 条款<3 union all select * from a where 条款=3 and 供应商 in(2,12)
SELECT * FROM TB WHERE 条款<>3 Or (供应商 IN(2,12) and 条款=3)
select * from A where 条款 in(1,2,3,4,5)
UNION ALL
SELECT * FROM TB WHERE 条款=3 AND 供应商 IN(2,12)???
/***********************************************--> 测试数据:[表A]
--> 测试时间:2009-08-13 09:15:48
--> 我的淘宝:<<戒色坊>> http://shop36766744.taobao.com/***********************************************/if object_id('[表A]') is not null drop table [表A]
create table [表A]([供应商] int,[条款] int)
insert [表A]
select 2,3 union all
select 12,3 union all
select 53,1 union all
select 45,4 union all
select 45,3 union all
select 564,3 select [供应商],[条款] from (
select [供应商],[条款],flag=case when [供应商]=2 or [供应商]=12 then 1 else [条款] end from [表A]
) t where flag<>3
/*
供应商 条款 flag
----------- ----------- -----------
2 3 1
12 3 1
53 1 1
45 4 4(4 行受影响)*/
drop table [表A]
union all
select * from a where 条款=3 and 供应商 in(2,12) --加上供应商为2,12中条款为3的记录或者如下:
select * from a where 条款>3
union all
select * from a where 条款<3
union all
select * from a where 条款=3 and 供应商 in(2,12)