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

    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0

    Help with creating SQL statemnt (sales made by employees)


    Hi,

    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
    Location
    Toronto Canada
    Posts
    27,212
    Rep Power
    4279
    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
    Posts
    90
    Rep Power
    3
    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