以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]SQL语句效率改进 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=187961) |
-- 作者:huaziqiao1976 -- 发布时间:2023/8/23 13:29:00 -- [求助]SQL语句效率改进 用SQL语句做数据更新,二三千行数据要近1分钟,效率不高,请求修改 Dim cmd As New SQLCommand cmd.C Dim dt As DataTable Dim Cols1() As String = {"f_zh","f_ye"} Dim Cols2() As String = {"f_zh","f_ye"} cmd.CommandText = "S*ELECT * From {表A} where f_zh In (S*elect f_zh FROM {表B})" dt = cmd.ExecuteReader(True) For Each dr1 As DataRow In dt.DataRows For Each dr As DataRow In DataTables("表B").DataRows If dr("f_zh") = dr1("f_zh") Then For i As Integer = 0 To Cols1.Length -1 dr("f_ye") = dr1("f_ye") Next Next
|
-- 作者:有点蓝 -- 发布时间:2023/8/23 13:41:00 -- 这代码想做什么? |
-- 作者:huaziqiao1976 -- 发布时间:2023/8/23 13:48:00 -- 在表A找到和表B账号(f_zh)相同的余额(f_ye)更新到表B [此贴子已经被作者于2023/8/23 13:53:04编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/8/23 13:54:00 -- 代码有2个遍历是完全没有必要的 For Each dr1 As DataRow In dt.DataRows DataTables("表B").replacefor("f_ye", dr1("f_ye") ,"f_zh=\'" & dr1("f_zh") & "\'") Next update b set a.f_ye = b.f_ye from 表B as b inner join 表A as a where a.f_zh=b.f_zh
|
-- 作者:huaziqiao1976 -- 发布时间:2023/8/23 14:18:00 -- update b set a.f_ye = b.f_ye from 表B as b inner join 表A as a where a.f_zh=b.f_zh 请救下蓝板,里面的a b 是不是等同于{表A} {表B}
|
-- 作者:有点蓝 -- 发布时间:2023/8/23 14:24:00 -- 是的 |