how do I solve the problem "ambiguous column name: n_name" and separate supplier and customer’s nation?
SELECT count(l_orderkey)
FROM lineitem
INNER JOIN orders ON lineitem.l_orderkey = orders.o_orderkey
INNER JOIN customer ON orders.o_custkey = customer.c_custkey
INNER JOIN nation ON customer.c_nationkey = nation.n_nationkey
INNER JOIN supplier ON lineitem.l_suppkey = supplier.s_suppkey
INNER JOIN nation ON supplier.s_nationkey = nation.n_nationkey
INNER JOIN region ON nation.n_regionkey = region.r_regionkey
WHERE n_name = "UNITED STATES" AND r_name = "AFRICA"
2
Answers
you can split the query in two parts :
And after that make a Sum of the count’s to get the final count result for the line order key as bellow :