SQL query question Well I\'m stuck.... I have a database with two tables, Produc
ID: 3733566 • Letter: S
Question
SQL query question
Well I'm stuck.... I have a database with two tables, Products and salesman. I am tasked with displaying the salesman_Firstname, salesman_Lastname colums from the salesman table as well as the Products_Price column from the Products table. I need only display the records where the totals (sum) of the Products_Price is greater than 10,000 for each salesman and order by the totals of the Products_Price. I know i need to use the join clause in this instance and the SUM(Products_Price) > 10000 statement but i just cant seem to make it work.. any help would be much appreciated.
Sorry the linking relationship between tables is salesman_ID ( products.salesman_ID and salesman.salesman_ID). There is a third table but i didnt think it was relevant as i all the information i have been asked to display is only in the products and salesman tables. the third table is departments (dept_ID, dept_name, dept_address, dept_phone) This table contains no relationships to the other 2 tables.
Explanation / Answer
The SQL query you need is:
SELECT A.salesman_Firstname, A.salesman_Lastname, B.Products_Price FROM (SELECT salesman_ID, salesman_Firstname, salesman_Lastname FROM salesman) as A, (SELECT salesman_ID, Products_Price FROM Products) WHERE A.salesman_ID = B.salesman_ID and SUM(b.Products_Price) > 10000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.