April 28th, 2013, 04:04 PM
Help with creating SQL statemnt (sales made by employees)
I am hoping someone can help me with an SQL query i am trying to construct in order to return how many properties each sales advisor has sold and in which month.
I need the query to display the following in a table
employee_id First name Last name Total Sales TimeofSale
1 John doe 2 02/12
2 MArie Claire 1 09/11
The tables i have are the following
1) sales_advisor (which contains 'sales_advisor_id' and 'TotalSales')
2) employee (which contains 'employee_id', 'f_name' and 'l_name')
3) sales_record (which contains 'TimeofSale')
Yes this is part of some University work, therefore i cant ask for it to be done for scratch just more of some advice. So, until now this is what i have put, however i am not getting the right outcome.
SELECT sales_advisor.employee_id, f_name, s_name, SUM(TotalSales) AS TotalSales
INNER JOIN sales_advisor = sales_advisor INNER JOIN
employee ON f_name = s_name
Please if someone can be generous enough to throw me some knowledge, will ve very appreciated, Thanks
April 28th, 2013, 04:35 PM
you will also need a GROUP BY clause for your sql statement
you will also need to fix your JOIN.
"INNER JOIN sales_advisor = sales_advisor"
the above line, makes no sense.
you will need to connect some column in the sales_record table with an equivalent column in the sales_advisor
INNER JOIN sales_adviser on sales_record.sales_advisor_id= sales_advisor.sales_adviser_id