使用mysql查询的结果作为下一步的where子句

brtdzjyr  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(335)

我想使用下面的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'
qhhrdooz

qhhrdooz1#

尝试使用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

相关问题