【问题标题】:checking the adjacent column value in mySQL检查 mySQL 中的相邻列值
【发布时间】:2014-03-31 18:44:55
【问题描述】:

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

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

    brendon      |    john             |    lee           |    tommey           |

    wilson       |    mark             |    allen         |    jill             |

我现在想做一个选择语句,在 surname 列中查找名称,然后检查 firstname 列的值。

因此,如果搜索是 wilson, john,我只想恢复该行。到目前为止,我有这个,这对于 surname 选择很好。

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

这是我有点卡住的地方。我尝试了 AND 语句,但这也带回了所有以 john 作为 firstname 的行。我在想 ORDER BY IF 语句可以做到这一点,但我可以让它工作..

提前感谢您的任何想法。

【问题讨论】:

  • 首先看到规范化 - 谁导演了 Paris, je t'aime四个房间 甚至是 绿野仙踪 ?

标签: mysql sql


【解决方案1】:
SELECT
    *
FROM
    films 
WHERE
    (
        director_sirname = 'wilson'
        AND director_firstname = 'john'
    ) OR
    (
        producer_sirname = 'wilson'
        AND producer_firstname = 'john'
    )
;

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2013-08-27
    • 2017-04-18
    相关资源
    最近更新 更多