gpt4 book ai didi

mysql - SQL:创建多列搜索查询

转载 作者:行者123 更新时间:2023-11-29 22:22:28 25 4
gpt4 key购买 nike

我这里有一个数据库表,其中包含示例条目:

enter image description here

我想要做的是创建一个查询,使用 LIKE 搜索 client_name,并且 client_name 应该具有类型、状态和信用额度,以及描笼涯或城市。

我尝试混合和匹配我的查询,但我似乎无法得到正确的查询。

例如,我尝试过这个:

select *
from client
where client_name like '%%'
having brgy = '' or city = ''
and type = '' and status = ''
and credit_limit = ''
order by client_name asc;

PS:我也想这样做,如果我搜索“anne”,所有带有“anne”的客户名称都会出现

最佳答案

确实需要括号。您不需要需要having条款。您确实需要了解等于和不等于之间的区别:

select *
from client
where client_name like '%%' and
(brgy <> '' or city <> '') and
type <> '' and status <> '' and
credit_limit <> ''
order by client_name asc;

注意:如果值实际上是 NULL与空白相反,则此版本将不起作用。然后您需要 is not null而不是<> '' .

关于mysql - SQL:创建多列搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30583623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com