我想使用以下MySql查询作为主查询中WHERE子句的输入,但是我找不到正确的方法来执行此操作。我可以使用任何网站或示例来学习如何执行此操作吗?
代码如下:
主要查询:
SELECT *, IF(SubQuery is true, 'Yes', 'No') AS Watched Distribution
FROM account
WHERE Watched Distribution LIKE 'Yes'
子查询:
SELECT account_id, IF(w.main_title RLIKE 'place holder for film
titels|nextfilm|nextfilm', 'Distribution', 'Non-distribution') AS Distribution
FROM watched w
WHERE Distribution LIKE 'Distribution'
最佳答案
尝试使用JOIN运算符和where子句,如下所示:
SELECT a.*, 'Yes'
FROM account a
JOIN watched w on w.account_id = a.account_id
where 'Distribution' in (IF(w.main_title RLIKE 'place holder for film
titels|nextfilm|nextfilm', 'Distribution', 'Non-distribution'))
请参见下面的示例:
https://www.sitepoint.com/community/t/mysql-question-how-to-us-an-as-field-in-the-where-clause/1188/5