1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    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
    FROM sales_record
    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
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Toronto Canada
    Rep Power
    you will also need a GROUP BY clause for your sql statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Rep Power
    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
    for examples
    INNER JOIN sales_adviser on sales_record.sales_advisor_id= sales_advisor.sales_adviser_id

IMN logo majestic logo threadwatch logo seochat tools logo