gpt4 book ai didi

mysql - 检查 mySQL 中相邻列的值

转载 作者:行者123 更新时间:2023-11-30 00:27:27 25 4
gpt4 key购买 nike

我有一个包含多个列的电影数据库,其中有 4 列。

director_surname |  director_firstname | producer_surname |  producer_firstname |
---------------------------------------------------------------------------------
frost | phil | wilson | john |

brendon | john | lee | tommey |

wilson | mark | allen | jill |

我现在想要执行一个 select 语句,在 surname 列中查找名称,然后检查 firstname 列中的值。

因此,如果搜索是wilson, john,我只想返回该行。到目前为止,我已经有了这个,这对于姓氏选择来说很好。

SELECT * FROM films 
WHERE CONCAT(director_surname, producer_surname)
LIKE '%wilson%';

这就是我有点卡住的地方。我尝试了 AND 语句,但这也会返回以 john 作为名字的所有行。我认为 ORDER BY IF 语句可以做到这一点,但我可以让它工作..

预先感谢您的任何想法。

最佳答案

SELECT
*
FROM
films
WHERE
(
director_sirname = 'wilson'
AND director_firstname = 'john'
) OR
(
producer_sirname = 'wilson'
AND producer_firstname = 'john'
)
;

关于mysql - 检查 mySQL 中相邻列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759430/

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