简体   繁体   中英

selecting in 4 tables with conditions

i need to select vbeln from likp and i have to select only vbeln that has been marked 'C' in vbuk. and from that likp-vbeln(delivery) i have to search/select for its carrier in vekp and after searching for the carrier I then have to search/select its shiptype from another table. i have table with 7 fields, in the code below im selecting some deliveries but i dont know how to add the condition in vbuk table because i dont need to select from vbuk. thanks. the code is below:

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.

You don't need to select from the table in order to join on it, just add VBUK to your join.

I notice that you haven't included an INTO clause, which is needed when you use a field-list.

Something like:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM