Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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 使用子查询更新查询_Mysql_Subquery_Where - Fatal编程技术网

Mysql 使用子查询更新查询

Mysql 使用子查询更新查询,mysql,subquery,where,Mysql,Subquery,Where,这是抽象SQL查询解决方案吗?我需要使用带有where的子查询更新行 希望不会误解您想要做的事情,请尝试以下查询: update articles join ( select parentid, count(*) cnt from articles group by parentid ) t on articles.id = t.parentid set articles.varcount = t.cnt where articles.parentid = '' 我认

这是抽象SQL查询解决方案吗?我需要使用带有
where
的子查询更新行


希望不会误解您想要做的事情,请尝试以下查询:

update articles
join (
    select parentid, count(*) cnt
    from articles
    group by parentid
) t on articles.id = t.parentid
set articles.varcount = t.cnt
where articles.parentid = ''

我认为您需要在子查询中创建一个别名。这只是一个
更新
查询。我们对你试图解决的实际问题一无所知。此外,请编辑您的帖子,以包含任何查询或样本数据以及格式良好的文本。请将代码、错误、样本数据或文本输出以纯文本形式发布在此处,而不是以图像形式发布,这些图像可能难以阅读,无法复制粘贴以帮助测试代码或在答案中使用,并且对使用屏幕阅读器的人不友好。您可以编辑问题以在问题正文中添加代码。使用
{}
按钮格式化任何代码块,或使用四个空格缩进以获得相同效果。
update articles
join (
    select parentid, count(*) cnt
    from articles
    group by parentid
) t on articles.id = t.parentid
set articles.varcount = t.cnt
where articles.parentid = ''