Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MySQL查询的结果作为下一步的WHERE子句_Mysql_Sql_Subquery - Fatal编程技术网

使用MySQL查询的结果作为下一步的WHERE子句

使用MySQL查询的结果作为下一步的WHERE子句,mysql,sql,subquery,Mysql,Sql,Subquery,我想使用以下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 'pl

我想使用以下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'

尝试使用连接运算符和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'))
见下例:


样本数据和期望的结果真的会有帮助。我知道!由于新的GDPR相关政策,很难共享此数据。。我知道这让我陷入了困境,所以任何关于如何在新查询中使用子查询的文档或课程的方向都会对我有很大帮助。所以你就组成了样本数据。我们不需要真实的数据,只需要示例来说明您的意图。