Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个忽略 WHERE 函数部分的 SQL 查询。
SELECT col1, col2, col3, col4 FROM table WHERE col1 = 'yes' AND col2 = 'no' AND col3 || col4 LIKE '%maybe%'
如果没有最后一个AND函数,它会带回正确的行,但是使用 LIKE 函数,它将带回 'no' in 的行col1。
AND
col1
我将猜测您打算LIKE分发该声明 - 在这种情况下您想要:
LIKE
SELECT col1, col2, col3, col4 FROM table WHERE col1 = 'yes' AND col2 = 'no' AND (col3 LIKE '%maybe%' OR col4 LIKE '%maybe%')
如果要连接col3and col4,mysql 中的正确语法是使用CONCAT函数:
col3
col4
SELECT col1, col2, col3, col4 FROM table WHERE col1 = 'yes' AND col2 = 'no' AND CONCAT(col3, col4) LIKE '%maybe%'
而|| 是 OR 运算符。
请在此处查看小提琴。