Trying to write a SELECT statement for a homework problem. I added a SUM function but not sure it can be used that way. As well as having 3 JOINs because the tables are distant from each other. Honestly if any of my current code is incorrect please tell me. But my main focus is how to limit the field "discontinued" in the table.
The question is: Draw from the sales data model to prepare a statement showing customer first name, customer e-mail address, product name, and total units, where total units is the sum of units in stock and units on order. Limit records to orders not discontinued (i.e., 'N' from the discontinued field). Create an alias for each field in the SELECT clause, including “Total Units” for the calculated column. Create and use an alias for each table in the FROM clause. Sort by total units.
The table: https://imgur.com/rdZthcH
SELECT customerFN AS “First Name”, customerEmail AS “Email”, productName AS “Product Name”, (SUM(unitsInStock)+SUM(unitsonorder)) AS "Total Units" FROM customer c JOIN order o ON c.customerID = o.customerID JOIN orderLine l ON o.orderID = l.orderID JOIN product p ON l.productCode = p.productCode WHERE
There is nothing after the WHERE clause because the code is incomplete. The code is incomplete because I believe that I need a WHERE clause of some sort to limit the "discontinued' field. I just don't know how to do that. I've looked up Where clauses and I think it would use >< or !=. But I don't know the function.