Skip to Content
0
Jun 25, 2009 at 03:56 PM

How to count multi table's records in one sql statement ?

42 Views

Dear Guru ,

I have 3 tables : mara , mvke , marc .

and now i would like to count the LVORM field if the material code is : A .....

I need these count result save in one internal table , jus like that :

matnr mara mvke marc

A 0 2 1

......

....

Is it possible to do that in one sql statement ?

here is my code , but it failure ....

SELECT A~MATNR

count( distinct A~LVORM ) as lvorm1

count( distinct B~LVORM ) as lvorm2

count( distinct C~LVORM ) as lvorm3

INTO CORRESPONDING FIELDS OF TABLE it_tab

FROM MARA AS A , MVKE AS B , MARC AS C

FOR ALL ENTRIES IN IT_MARA

WHERE ( A~MATNR = it_mara-matnr

AND B~MATNR = it_mara-matnr

AND C~MATNR = it_mara-matnr )

AND

( ALVORM = 'X' OR BLVORM = 'X' OR C~LVORM = 'X' )

group by a~matnr .

Please help ...

Thanks .

Best Rds,

Carlos