I have 4 tables like this (you can ignore table B because this problem did not use that table)
I want to show the sum of 'total' for each 'sales_id' from table 'sales_detail'
What I want (the result) is like this :
sales_id | total
S01 | 3
S02 | 2
S03 | 4
S04 | 1
S05 | 2
S05 | 3
sales_id = any (select sales_id
where customer_id = any (select customer_id
You are just so far off track that a simple comment won't help. Your query only concerns one table,
sales_detail. It has nothing to do with the other two.
And, it is just an aggregation query:
select sd.sales_id, sum(sd.total) from sales_detail sd group by sd.sales_id;
This is actually pretty close to what the question itself is asking.