以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  统计表中不重复值的数量效率问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=169968)

--  作者:z769036165
--  发布时间:2021/7/7 20:37:00
--  统计表中不重复值的数量效率问题
For Each dr As DataRow In DataTables("表A").DataRows
    dr("价格数量") =   DataTables("表B").GetValues("单价","编码 = \'"& dr("编码") &"\'").Count
Next

A表5000行,B表5万行数据左右,目前上述代码效率在1分钟左右,这个太慢了,有没有其他办法能快速统计这样不重复值得数量

--  作者:有点蓝
--  发布时间:2021/7/8 8:32:00
--  
用sql,类似

updat表A set 价格数量=数量 from 表A inner join (select 编码,count(单价) as 数量 from (select distinct 编码,单价 from 表B) as a group by 编码) on 表A.编码=表B.编码