选择mysql中的更新 [英] select update in mysql
问题描述
如何使用限制0,1从mysql中选择一行并更新所选行中的一列
例如:
update(从billgeneration limit 0,1中选择*)作为d set TotalAmount = 2000
how to select one row from mysql using limit 0,1 and update one column from selected row
eg:
update ( select * from billgeneration limit 0,1 ) as d set TotalAmount = 2000
推荐答案
首先,你在一个DataSet中获取总信息(或)DataTable。
之后,您可以使用foreach循环,获取每一行信息。在foreach里面你写了更新查询。这是应用方面的...
ex:
First of all you fetch total information in one DataSet (or) DataTable.
After that you can use foreach loop , fetch the each and every row information. Inside the foreach you write you update query. this is in application wise...
ex:
DataTable dt=//total data;
foreach(DataRow dr in dt.Rows)
{
//your update query
}
在DB本身也可以这样做
Ex:
In DB itself also you can do this
Ex:
DataSet ds= //data;
string data =ds.GetXML();
在SQL SP中你自己可以按照以下步骤实现此目的
获取XML路径信息并将其存储在一个temprory表中。然后,
In your SQL SP itself you can follow the below steps to achieve this
Fetch the XML path information and store it in one temprory table. Then,
DECLARE @MINCOUNT INT , @MAXCOUNT INT
SELECT @MAXCOUNT = COUNT(*) FROM #TEMPTable
SET @MINCOUNT = 1
DECLARE @Update_Count VARCHAR(10)
SET @Update_Count=0
While( @MINCOUNT<= @MAXCOUNT)
BEGIN
//UPDATE QUERY
//SET @Update_Count=@Update_Count+1
SET @MINCOUNT= @MINCOUNT+1
END
这是DB方......
THIS is DB side....
update ( select * from billgeneration limit 0,1 ) as d set TotalAmount = 2000
在mysql中是不可能的。但是,您必须先选择然后迭代结果,然后在每次迭代时触发更新。程序或功能是这样做的好选择。
It is not possible in mysql. However you have to select first then iterate over the result and then fire the update on each itaration. Procedure or function is the good choice to do this.
您好,
您可以像直接更新一样
Hi,
you can do like direct Update as
update billgeneration set TotalAmount = 2000 WHERE limit IN(0,1)
请检查以下链接
更新语法 [ ^ ]
问候,
GVPrabu
Check the following link
UPDATE Syntax[^]
Regards,
GVPrabu
这篇关于选择mysql中的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!