Hello,
I need some help with a MySQL query, probably a JOIN. Here is the situation:
I have two tables. The first one contains customer info.
Table CUSTOMERS
id | name | address
id ... customer ID (MEDIUMINT, autoincrement)
name ... customer name, for example John Doe
address ... customer shipping address
Then I have the second table which contains sale info from all customers.
Table SALES
id | dt | customer | amount | shipped
id ... is sale ID ( INT, autoincrement)
dt ... date of the sale (DATE, 00-00-0000)
customer ... customer ID number, the same as "id" in table CUSTOMERS
amount ... sale amount in dollars
shipped ... TINYINT, 1 = shipped, 0 = not yet shiped
Now what I want to do is create a query which will contain this info for EACH customer:
Customer ID | Customer name | Customer address | Sum of ALL sales amount | Sum of SHIPPED sales amount
So basically I want a query which will return id, name, address, and two amount sums for each customer. Is such a query possible in this situation?
I tried with JOIN command but couldn't get iw working, any ideas?
Thanks for any help!
I need some help with a MySQL query, probably a JOIN. Here is the situation:
I have two tables. The first one contains customer info.
Table CUSTOMERS
id | name | address
id ... customer ID (MEDIUMINT, autoincrement)
name ... customer name, for example John Doe
address ... customer shipping address
Then I have the second table which contains sale info from all customers.
Table SALES
id | dt | customer | amount | shipped
id ... is sale ID ( INT, autoincrement)
dt ... date of the sale (DATE, 00-00-0000)
customer ... customer ID number, the same as "id" in table CUSTOMERS
amount ... sale amount in dollars
shipped ... TINYINT, 1 = shipped, 0 = not yet shiped
Now what I want to do is create a query which will contain this info for EACH customer:
Customer ID | Customer name | Customer address | Sum of ALL sales amount | Sum of SHIPPED sales amount
So basically I want a query which will return id, name, address, and two amount sums for each customer. Is such a query possible in this situation?
I tried with JOIN command but couldn't get iw working, any ideas?
Thanks for any help!