I don’t understand how to “combine” two tables so that I can generate an answer to this.
Basically I have a CAP database and I’m only concerned with two tables:
ORDERS (ordno, month, year, cid, aid, pid, qty, dollars)
PRODUCTS (pid, pname, city, quantity, price)
I know that i need to generate a new table like the following to get the answer:
Temp (month, year, pname, price)
The way I tried to do it is:
Temp = Select * from (
(Select month, year from Orders)
join
(Select price, pname from Products)
on
orders.pid = products.pid )
The above query gives me an error that I don’t understand: Every derived table must have its own alias.
The next step i’m pretty sure is:
Answer = select max(price), pname, month from Temp where year = 2011 group by month;
I am very new to SQL. If you guys could help me that would be great. If there is a website that can help me learn SQL better please let me know. Thanks!
EDIT: also if there is more than one product that has max price then you need to list all of them for that month.
EDIT 2: SOLVED THANKS!!
EDIT
If the price of the product ever changes, you will not get a meaningful result.
FYI This is how you give a derived table an alias.