dwm_dws_cbsjbz 小表,dwm_sap_zsdt066大表 SELECT ZYEAR,ZMONTH,ZZCPXLT,SUM(VVD02) VVD02 FROM( select a.ZYEAR, a.ZMONTH, a.KAUFN, a.KDPOS, a.MATNR, a.AUART, a.VVD02, c.ZZCPXLT from dwm_dws_cbsjbz a inner join dwm_sap_zsdt066 c on a.KAUFN = c.VBELN and a.KDPOS = c.POSNR where a.AUART = 'OR1' AND a.ZYEAR = '2023' and a.ZMONTH = '04' ) AS SFDF GROUP BY ZYEAR,ZMONTH,ZZCPXLT 优化这个语句
时间: 2024-03-21 21:40:25 浏览: 104
Decawave1.zip_Decawave_decawave dw1000 pdf_dwm1000 datasheet_lan
这个语句的优化可以从以下几个方面入手:
1. 添加索引:在dwm_dws_cbsjbz表的KAUFN和KDPOS列上添加联合索引,以及在dwm_sap_zsdt066表的VBELN和POSNR列上添加联合索引,可以提高连接查询的效率。
2. 使用子查询:将连接查询的结果作为子查询,避免了大表和小表的直接连接,减少了计算量。
优化后的SQL语句如下:
```
SELECT ZYEAR, ZMONTH, ZZCPXLT, SUM(VVD02) VVD02
FROM(
SELECT a.ZYEAR, a.ZMONTH, a.VVD02, c.ZZCPXLT
FROM dwm_dws_cbsjbz a
INNER JOIN (
SELECT VBELN, POSNR, ZZCPXLT
FROM dwm_sap_zsdt066
WHERE VBELN IN (
SELECT KAUFN
FROM dwm_dws_cbsjbz
WHERE AUART = 'OR1' AND ZYEAR = '2023' AND ZMONTH = '04'
)
) c ON a.KAUFN = c.VBELN AND a.KDPOS = c.POSNR
WHERE a.AUART = 'OR1' AND a.ZYEAR = '2023' AND a.ZMONTH = '04'
) AS SFDF
GROUP BY ZYEAR, ZMONTH, ZZCPXLT;
```
以上是一种可能的优化方式,具体实现还需要根据你的实际情况进行调整。
阅读全文