我一直使用MS Access,并且以前使用我的主数据表创建了汇总表(maketable查询),即我的主数据具有发票上的所有销售信息,然后我按客户创建了销售汇总表,这意味着通过Intranet页面查看时,该表中的行减少了,从而显示得更快。
我现在决定移至MYSQL,并且没有maketable命令,但是我可以基于选择查询创建一个名为“ customersales”的表。我的主表中有100万行,称为“销售”。这样,完成过程需要257秒,在我看来这很慢。结果实际上将47000条记录返回到新表中
下面是我的create table语句:-
CREATE DEFINER = root
@ localhost
程序'CREATE_SALESCUSTOMER'()
开始
SET SQL_SAFE_UPDATES = 0;
从salescustomer中删除;
INSERT
INTO SALESCUSTOMER(SumOfNET, SUMOFGROSS, SumOfQTY, SUMOFSQMQUANTITY,
SUMOFMARGIN, SumOfBUDGETNET,SumOfBUDGETMARGIN,SumOfBUDGETSQM,
VKORG,VKBURORDER,VKGRPORDER,SALESGROUPORDER,SALESOFFICEORDER,
CUSTOMER,NAME1,KUNN2,PARTNERNAME,PERDE,GJAHR,SALESDIRECTOR,
SALESDIRECTORNAME,VKBUR,VKGRP,SALESGROUP,SALESOFFICE,
STRAS,ORT02,ORT01, COUNTY,PSTLZ,TELF1,konda,kondatext
)
SELECT Sum(SALES.NET_SALES) AS SumOfNET,Sum(SALES.NET_SALES) AS SUMOFGROSS,
Sum(SALES.QTY) AS SumOfQTY,
Sum(SALES.SUMOFSQMQUANTITY) AS SUMOFSQMQUANTITY,
Sum(SALES.UKMARGIN) AS SUMOFMARGIN,
Sum(SALES.BUDGETNET) AS SumOfBUDGETNET,
Sum(SALES.BUDGETMARGIN) AS SumOfBUDGETMARGIN,
Sum(SALES.BUDGETSQM) AS SumOfBUDGETSQM,
SALES.VKORG,SALES.VKBURORDER,
SALES.VKGRPORDER,SALES.SALESGROUPORDER,
SALES.SALESOFFICEORDER,SALES.CUSTOMER,SALES.NAME1,SALES.KUNN2,
SALES.PARTNERNAME,SALES.PERDE,SALES.GJAHR,SALES.SALESDIRECTOR,
SALES.SALESDIRECTORNAME,SALES.VKBUR,SALES.VKGRP,SALES.SALESGROUP,
SALES.SALESOFFICE,STRAS,ORT02,ORT01, COUNTY,PSTLZ,TELF1,
konda,kondatext
FROM SALES
GROUP BY konda,kondatext,SALES.VKORG,SALES.VKBURORDER,SALES.VKGRPORDER,
SALES.SALESGROUPORDER,SALES.SALESOFFICEORDER,SALES.CUSTOMER,
SALES.NAME1,SALES.KUNN2,SALES.PARTNERNAME,SALES.PERDE,
SALES.GJAHR;
有人可以帮忙吗,我做错了吗,速度正常吗?抱歉,MYSQL的新手
谢谢 凯文
答案 0 :(得分:0)
不要每次都从头开始重建摘要表。而是每天(或每周或每小时或任何时间)增补。通常最好用Sub CopyPasteBetweenWorkbooks()
Dim wbCopy As Workbook
Dim wbPaste As Workbook
Dim wsCopy As Worksheet
Dim wsPaste As Worksheet
Set wbCopy = Workbooks("Book1.xlsx")
Set wsCopy = wbCopy.Sheets("Sheet1")
Set wbPaste = Workbooks("Book2.xlsx")
Set wsPaste = wbPaste.Sheets("Sheet1")
With wsPaste
wsCopy.Range("A1").Copy Destination:= _
.Range("C" & .Cells(.Cells.Rows.Count, "C").End(xlUp).Row + 1)
wsCopy.Range("B1").Copy Destination:= _
.Range("F" & .Cells(.Cells.Rows.Count, "F").End(xlUp).Row + 1)
End With
End Sub
来完成。确保有一些专栏,以便您可以“记住您上次离开的地方”。
这具有以下副作用:每次不会传递完整的47K行,并且不会删除表,从而使您暂时没有任何数据。