你能用 MySQL 做一个 For Each Row 循环吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7990227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you do a For Each Row loop using MySQL?
提问by zechdc
My question is related to the answer found in this post by user Consultuning on Oct 22 '09 at 18:31: mysql query to dynamically convert row data to columns
我的问题与用户Consultuning 于 09 年 10 月 22 日 18:31在这篇文章中找到的答案有关: mysql query to dynamic convert row data to columns
It appears that Consultuning'sanswer contains some MySQL with a For Each row
loop.
看来Consultuning 的答案包含一些带有For Each row
循环的MySQL 。
Can you do a For Each Row
loop using MySQL?
你能用For Each Row
MySQL做一个循环吗?
If so, could someone give me a link to the MySQL For Each Row
documentation?
如果是这样,有人可以给我一个指向 MySQLFor Each Row
文档的链接吗?
采纳答案by panupan
The closest thing to "for each" is probably MySQL Procedure using Cursor and LOOP.
最接近“for each”的可能是MySQL Procedure using Cursor 和 LOOP。
回答by Kudapucat
Not a for each exactly, but you can do nested SQL
不是每个都准确,但您可以执行嵌套 SQL
SELECT
distinct a.ID,
a.col2,
(SELECT
SUM(b.size)
FROM
tableb b
WHERE
b.id = a.col3)
FROM
tablea a
回答by Zohaib
In the link you provided, thats not a loop in sql...
在您提供的链接中,这不是 sql 中的循环...
thats a loop in programming language
那是编程语言中的循环
they are first getting list of all distinct districts, and then for each district executing query again.
他们首先获取所有不同地区的列表,然后对每个地区再次执行查询。