I have 3 tables a, b, and c. Table a contains the ids of the stores, their earning date, and count of sale (flight tickets).
Table b contains the id, sale date, and count of clothing orders.
Table c contains the id, date and total count.
SQL> select * from a;
STOREID EARNINGDATE COUNT_FLIGHT_TICKETS
-------------------- ----------- ----------------
store01 14980000 10
store01 14980001 32
store02 14980000 134
SQL> select * from b;
STOREID EARNINGDATE CLOTHES_SALE_COUNT
-------------------- ----------- ---------------
store01 14980000 6
store02 14980000 6
SQL> select * from c;
STOREID EARNINGDATE TOTAL_SALE_COUNT
-------------------- ----------- -------------
store01 14980001 32
store01 14980000 16
store02 14980000 134
Given above the tables, I have to print all the stores ids, with their date of earning for total sale, flight sale, and clothing sale.
|StoreId | EarningDate | FlightCount | ClothingCount | TotalCount |
I have used below query, but failing to get the above.
select b.storeId , sum(a.COUNT_FLIGHT_TICKETS),
sum(b.CLOTHES_SALE_COUNT), sum (c.TOTAL_SALE_COUNT)
from a
full outer join b on a.storeId = b.storeId
and a.EarningDate = b.earningdate
full outer join c on a.storeId = c.storeId
and a.earningDate = b.earningDate group by a.storeId;
This query does not give all the rows and having some bug.
STOREID flight clothing total
------ --------- --------- --------------------
store02 134 6 134
store01 52 12 48
Can someone help me to correct this query to get the expected output?
group by a.storeId?