日期:2014-05-17 浏览次数:20475 次
SELECT * FROM TEST
WHERE 主键 NOT IN
(
SELECT 主键 FROM TEST
WHERE ColumnA='A' AND ColumnB='B'
)
SELECT * FROM TEST
WHERE NOT (ColumnA='A' AND ColumnB='B')
SELECT * FROM TEST
WHERE ((ColumnA='A' AND ColumnB<>'B')
OR (ColumnA<>'A' AND ColumnB<>'B')
OR (ColumnA<>'A' AND ColumnB='B')
)
select * from TEST as a
where not exists (select 1 from TEST
WHERE ColumnA='A' AND ColumnB='B' and 主键=a.主键)
--最好的解决方法
declare @StartTime datetime
set @StartTime = getdate()
[你的SQL 语句]
select datediff(ms,@StartTime,getdate())
--时间最小,语句最优
--用于生成示例数据,这里是100W条数据
if OBJECT_ID('Test') is not null drop table Test
create table Test(ID [bigint] identity primary key,
ColumnA char(1) NULL,
ColumnB char(1) NULL)
INSERT INTO dbo.Test SELECT case
when abs(checksum(newid()))%(3) = 0 then char(65+abs(checksum(newid()))%(26))
when abs(checksum(newid()))%(2) = 0 then char(97+abs(checksum(newid()))%(26)) end, case
when abs(checksum(newid()))%(3) = 0 then char(65+abs(checksum(newid()))%(26))
when abs(checksum(newid()))%(2) = 0 then char(97+abs(checksum(newid()))%(26)) end
DECLARE @i AS INT, @rc AS INT,@max int;
SET @rc = 1;
SET @max = 1000000;
set @i = ceiling(log10(@max)/LOG10(2))-1;
WHILE @rc <= @i
BEGIN
INSERT INTO dbo.Test SELECT case