MSSQL:WHERE 字段不等于字符串列表
MSSQL: WHERE Field Does Not Equal List of Strings
------------UPDATED______________
如果 A 列等于字符串列表,我想删除数据行 table。我可以在 Python 代码中执行此操作,但不知道如何在 MSSQL 中执行此操作。
下面的屏幕截图显示了我拥有的 table 与我想要的 table 的示例。如果该值介于 4800 和 4900 之间,我想删除该行。虽然 A 列由所有字符串值组成。
请查看下面我的 Python 代码:
import numpy as np
df_adhoc_1_final['A'] = df_adhoc_1_final['A'].astype(str)
aircraft_num = np.arange(4888, 4903).astype(str)
for i in aircraft_num:
df_adhoc_1_final = df_adhoc_1_final[df_adhoc_1_final['A'].str.contains(i) == False]
编辑 'A' 为字符串
declare @example as table (
exampleid int identity(1,1) not null primary key clustered
, A nvarchar(255) not null
, value_ int not null
);
insert into @example (a, value_)
select '4000', 22 union all
select '4888', 44 union all
select '4895', 33 union all
select '4933', 11 union all
select '5000', 14;
select A
, value_
from @example
where cast(a as int) not between 4800 and 4900;
结果集:
A Value_
4000 22
4933 11
5000 14
------------UPDATED______________
如果 A 列等于字符串列表,我想删除数据行 table。我可以在 Python 代码中执行此操作,但不知道如何在 MSSQL 中执行此操作。
下面的屏幕截图显示了我拥有的 table 与我想要的 table 的示例。如果该值介于 4800 和 4900 之间,我想删除该行。虽然 A 列由所有字符串值组成。
请查看下面我的 Python 代码:
import numpy as np
df_adhoc_1_final['A'] = df_adhoc_1_final['A'].astype(str)
aircraft_num = np.arange(4888, 4903).astype(str)
for i in aircraft_num:
df_adhoc_1_final = df_adhoc_1_final[df_adhoc_1_final['A'].str.contains(i) == False]
编辑 'A' 为字符串
declare @example as table (
exampleid int identity(1,1) not null primary key clustered
, A nvarchar(255) not null
, value_ int not null
);
insert into @example (a, value_)
select '4000', 22 union all
select '4888', 44 union all
select '4895', 33 union all
select '4933', 11 union all
select '5000', 14;
select A
, value_
from @example
where cast(a as int) not between 4800 and 4900;
结果集:
A Value_
4000 22
4933 11
5000 14