gpt4 book ai didi

mysql - 无法理解 LIKE 行为

转载 作者:行者123 更新时间:2023-12-01 00:45:12 27 4
gpt4 key购买 nike

考虑以下两个表:

系列

id  name            screen_name     deleted_at
9 Series Name 9 Screen Name 9 NULL
11 Series Oneb seriesoneb NULL
15 Mad Dogs maddogs NULL

门票

id  series_id   subject     deleted_at
8 15 Subject 8 NULL
13 11 Subject 13 NULL
28 9 Subject 28 NULL
34 11 Subject 34 NULL
37 9 Subject 37 NULL
41 9 Subject 41 NULL
48 9 Subject 48 NULL

以下查询怎么可能:

SELECT *
FROM `tickets`
WHERE (
SELECT count( * )
FROM `series`
WHERE `series`.`deleted_at` IS NULL
AND `tickets`.`series_id` = `series`.`id`
AND screen_name LIKE '%series name%'
OR name LIKE '%series name%'
AND `series`.`deleted_at` IS NULL
)

给我7行,不应该是6吗?

最佳答案

尝试为 OR 条件添加括号,如下所示

SELECT *
FROM `tickets`
WHERE (
SELECT count( * )
FROM `series`
WHERE `series`.`deleted_at` IS NULL
AND `tickets`.`series_id` = `series`.`id`
AND (screen_name LIKE '%series name%' OR name LIKE '%series name%')
AND `series`.`deleted_at` IS NULL
)

关于mysql - 无法理解 LIKE 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23062353/

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