spiderbaby
Programmer
I need to list sales volume which is the total of all orders by state, my problem is that I can't get the state's orders to total correctly. Here's what I have so far, and it's working with an Access database using VB.NET's built in query builder to do the statement.
The tables look like this:
Customers: cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email
Orders: order_num, order_date, cust_id
OrderItems: order_num, order_item, prod_id, quantity, item_price
Products: prod_id, vend_id, prod_name, prod_price, prod_desc
Vendors: vend_id, vend_name, vend_address, vend_state, vend_zip, vend_country.
This is what I have so far:
SELECT (SELECT cust_state FROM customers WHERE customers.cust_id = orders.cust_id GROUP BY cust_id, cust_state) AS customer_state, (SELECT SUM(item_price*quantity) FROM orderitems WHERE orderitems.order_num = orders.order_num GROUP BY order_num) AS volume
FROM (Customers INNER JOIN Orders ON Customers.cust_id = Orders.cust_id) GROUP BY cust_state, orders.cust_id, orders.order_num
This gives me:
customer_state volume
AZ 1696
IL 189.6
IN 329.6
MI 1648
MI 1867.5
What am I doing wrong? And is there a way to do this without an INNER JOIN? Any help would be greatly appreciated!!!
The tables look like this:
Customers: cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email
Orders: order_num, order_date, cust_id
OrderItems: order_num, order_item, prod_id, quantity, item_price
Products: prod_id, vend_id, prod_name, prod_price, prod_desc
Vendors: vend_id, vend_name, vend_address, vend_state, vend_zip, vend_country.
This is what I have so far:
SELECT (SELECT cust_state FROM customers WHERE customers.cust_id = orders.cust_id GROUP BY cust_id, cust_state) AS customer_state, (SELECT SUM(item_price*quantity) FROM orderitems WHERE orderitems.order_num = orders.order_num GROUP BY order_num) AS volume
FROM (Customers INNER JOIN Orders ON Customers.cust_id = Orders.cust_id) GROUP BY cust_state, orders.cust_id, orders.order_num
This gives me:
customer_state volume
AZ 1696
IL 189.6
IN 329.6
MI 1648
MI 1867.5
What am I doing wrong? And is there a way to do this without an INNER JOIN? Any help would be greatly appreciated!!!