我需要从likp中选择vbeln,我必须只选择在vbuk中标记为“C”的vbeln。从那个likp-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.
答案 0 :(得分:1)
您无需从表格中选择加入,只需将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.