like 函数中的多个条件
Multiple conditions in a like function
我有一组数据,每个点都以 AB
、PO
或 LV
开头。还有一些条目包含我不想要的东西,例如 MC
或 BV
。我也有一些日期,它看起来像这样。
Select distinct clm.Theletter, clm.thenotedate, clm.theorigdate
from table.table
where clm.thenotedate>= ''2018-01-21'' and clm.theorigdate>''2018-01-01''
and clm.Theletter_NUM LIKE ''HP%''
order by clm.thenotedate asc
);
我得到了一个以 AB
开头的所有我想要的列表,但我还想要以 PO
和 LV
开头的东西?我在第一个 LIKE 之后尝试使用 OR,但它似乎忽略了日期函数并检索了 2018-01-01 之前以 PO
和 LV
开头的所有内容,这很多。
如果你这样做可能是最简单的:
. . . and
left(clm.Theletter_NUM, 2) in ('AB', 'PO', 'LV')
大多数数据库支持字符串的 left()
函数。如果不是,只需使用适当的子字符串函数即可。
你需要在第一个赞之后重新写下行名。
Select *
From table
Where row like 1 or row like 2
或者您可以使用 in
Where row in ('1', '2', '3')
我有一组数据,每个点都以 AB
、PO
或 LV
开头。还有一些条目包含我不想要的东西,例如 MC
或 BV
。我也有一些日期,它看起来像这样。
Select distinct clm.Theletter, clm.thenotedate, clm.theorigdate
from table.table
where clm.thenotedate>= ''2018-01-21'' and clm.theorigdate>''2018-01-01''
and clm.Theletter_NUM LIKE ''HP%''
order by clm.thenotedate asc
);
我得到了一个以 AB
开头的所有我想要的列表,但我还想要以 PO
和 LV
开头的东西?我在第一个 LIKE 之后尝试使用 OR,但它似乎忽略了日期函数并检索了 2018-01-01 之前以 PO
和 LV
开头的所有内容,这很多。
如果你这样做可能是最简单的:
. . . and
left(clm.Theletter_NUM, 2) in ('AB', 'PO', 'LV')
大多数数据库支持字符串的 left()
函数。如果不是,只需使用适当的子字符串函数即可。
你需要在第一个赞之后重新写下行名。
Select *
From table
Where row like 1 or row like 2
或者您可以使用 in
Where row in ('1', '2', '3')