【发布时间】:2023-04-02 12:31:01
【问题描述】:
我尝试在WHERE 子句中对同一列使用AND,但它没有给我任何输出。但是数据集中有两个满足给定条件的客户名称。我哪里出错了?
SELECT CONCAT(c.CustFirstName," ",c.CustLastName) AS CustomerName
FROM Musical_Preferences mp
JOIN Customers c ON c.CustomerID = mp.CustomerID
WHERE mp.StyleID = 15 AND mp.StyleID = 24;
当我将OR 用于WHERE 子句中的同一列时,上述查询运行良好,但为什么不用于AND?
我的数据:
CustomerID CustFirstName CustLastName CustStreetAddress CustCity CustState CustZipCode CustPhoneNumber CustomerID StyleID PreferenceSeq 10001 Doris Hartwig 4726 - 11th Ave. N.E.西雅图 WA 98105 555-2671 10001 10 2 10001 Doris Hartwig 4726 - 11th Ave. N.E.西雅图 WA 98105 555-2671 10001 22 1【问题讨论】:
-
这应该可以。您定义了完全相同的条件
mp.StyleID = 24 and mp.StyleID = 24。你能展示一些示例数据吗? -
我投票结束,因为“愚蠢”
-
“看起来 MySQL 工作台只考虑第一个条件”:你为什么这么说?你的表中有什么数据,你期望什么输出,你得到了什么?
-
CustomerID CustFirstName CustLastName CustStreetAddress CustCity CustState CustZipCode CustPhoneNumber CustomerID StyleID PreferenceSeq 10001 Doris Hartwig 4726 - 11th Ave. N.E.西雅图 WA 98105 555-2671 10001 10 2 10001 Doris Hartwig 4726 - 11th Ave. N.E.西雅图 WA 98105 555-2671 10001 22 1
-
@Sree 你能把这些数据放在问题中而不是评论中吗?你不能在评论中格式化它