我需要从likp中选择vbeln,我必须只选择vbuk中标记为'C'的vbeln。我必须在vekp中搜索/选择它的承运人,然后在搜索承运人后,我必须从另一个表中搜索/选择它的船型。我有7个字段的表,在下面的代码中我选择了一些交付,但我不知道如何在vbuk表中添加条件,因为我不需要从vbuk中选择。谢谢。代码如下:
SELECT likp~vbeln
tab~shiptype
vekp~carrier
vekp~service
COUNT( DISTINCT vekp~shipment )
SUM( vekp~packagecount )
SUM( vekp~rate ) FROM vekp
INNER JOIN tab
ON tab~carrier = vekp~carrier INNER JOIN likp
ON vekp~delivery = likp~vbeln INTO itab
WHERE likp~erdat IN so_date AND
vekp~delivery = likp~vbeln AND
vekp~carrier = tab~code
GROUP BY vbeln shiptype carrier service.
您不需要从表中进行选择以连接它,只需将VBUK添加到您的连接中。
我注意到您没有包含INTO子句,这在使用字段列表时是必需的。
类似:
SELECT likp~vbeln
tab~shiptype
vekp~carrier
vekp~service
COUNT( DISTINCT vekp~shipment )
SUM( vekp~packagecount )
SUM( vekp~rate )
INTO (field1, fied2, etc) "<=== Change1
FROM vekp
INNER JOIN tab
ON tab~carrier = vekp~carrier INNER JOIN likp
ON vekp~delivery = likp~vbeln INTO itab
INNER JOIN VBUK "<=== Change2
ON likp~vbeln = vbuk~vbeln
WHERE likp~erdat IN so_date AND
vekp~delivery = likp~vbeln AND
vekp~carrier = tab~code AND
vbuk~fieldtocheck = 'C' "<=== Change3
GROUP BY vbeln shiptype carrier service.