简体   繁体   English

带有SELECT语句和LIKE运算符的MySQL SELECT

[英]MySql SELECT with if statement and LIKE operator

I am working on an advertisement site. 我正在一个广告站点上工作。

I have one table with a column for each day. 我每天有一张桌子,有一栏。 I need to check in the table which ads is saved as default to update only those ads. 我需要在表格中检查哪些广告被保存为默认广告,以仅更新那些广告。

I have tried this, but it not working. 我已经尝试过了,但是没有用。

SELECT Monday if (Monday LIKE '%default%'),
Tuesday if (Tuesday LIKE '%default%')
FROM `Ad_Relationshp`

MySql gives me this error: #1064 - You have an error in your SQL syntax; MySql给我这个错误:#1064-您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if (Monday LIKE '%default%') FROM Ad_Relationshp LIMIT 0,' at line 1. I have tried changing the syntax to everything I can think off, but I still get the same error. 在第1行的“ if(Monday LIKE'%default%')FROM Ad_Relationshp LIMIT 0,”附近检查与您的MySQL服务器版本对应的手册以使用正确的语法。我尝试将语法更改为我能想到的所有内容,但仍然出现相同的错误。

you are using the if conditional branching which is only possible in procedures and triggers,use the if function. 您正在使用仅在过程和触发器中才有可能的if条件分支,请使用if函数。

SELECT if (`Monday` LIKE '%default%',`Monday`,''),
if (`Tuesday` LIKE '%default%',`Tuesday`,'')
FROM `Ad_Relationshp`


SELECT `Monday`,`Tuesday`
FROM `Ad_Relationshp`
WHERE `Monday` LIKE '%default%'
OR `Tuesday` LIKE '%default%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM