Practicing with the northwind database shown below:
I'm trying to understand how to perform a crosstab while using both the orders and the order_details tables. The crosstab includes the employee_id and the ship_country from the orders table and the unit_price from the order_details table
Sample data from orders table:
Sample data from the order_details table:
sample data order_details table
I thought the following would work but I couldn't get it to run:
with my_table as (
select o.employee_id, o.ship_country, od.unit_price
from orders o
join order_details od on o.order_id = od.order_id)
select *
from crosstab('select employee_id, ship_country, unit_price from my_table')
as final_result(EmployeeID text, Austria numeric, Finland numeric, Italy numeric, France numeric,
Germany numeric, Brazil numeric, Belgium numeric, Switzerland numeric);
Any thoughts and how to get this working are much appreciated. The issue seems to be that it doesn't recognize the relation to my_table. I did run the 'create extension tablefunc;' command too without issue.