March 26, 2018 at 1:40 pm
I am trying to figure out how to pull the data from two tables where I can return firstname, lastname, item, price and the % of total price for each customer.
Two tables:
Customers (customerid, firstname, lastname, city, state)
Items_ordered ( customerid,ordered_date,item,quantity,price)
This statement will only return the first customer. How can you get a SQL statement that will go row by row and return all the information?
SELECT firstname, lastname, price, price/SUM(price)
FROM customers C
JOIN items_ordered O ON (C.customerid=O.customerid);
March 26, 2018 at 1:47 pm
Please don't post the same question multiple times. It causes far more problems than it solves (it solves none, basically).
The original thread, which already has one reply, can be found at https://www.sqlservercentral.com/Forums/1929260/Correlated-subquery-using-two-different-tables
Cheers!
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply