I'm having a problem putting this concept into SQL. I'm hoping someone can help....
Let's say I have tables CUSTOMERS and ORDERS.
CUSTOMERS is straight forward, 1 record for each customer info.
ORDERS contains one record for each Order placed. ORDER records contain a CustomerID and an OrderType (integer).
Let's say there are 5 possible OrderTypes(1-5). A customer may have no orders or they could have multiple orders, each ORDER record has an OrderType (a value between 1 and 5).
I want to create a SELECT query that produces a single record for each CUSTOMER. Each output record needs to contain a count of the number of ORDERS of OrderType=1, a count of the number of ORDERS of OrderType=2, a count of the number of ORDERS of OrderType=3, etc. (for that CUSTOMER)
I know how to create this beast in MS-Access using the DCOUNT function, but I am using SQL Server here.
Any suggestions please?
Let's say I have tables CUSTOMERS and ORDERS.
CUSTOMERS is straight forward, 1 record for each customer info.
ORDERS contains one record for each Order placed. ORDER records contain a CustomerID and an OrderType (integer).
Let's say there are 5 possible OrderTypes(1-5). A customer may have no orders or they could have multiple orders, each ORDER record has an OrderType (a value between 1 and 5).
I want to create a SELECT query that produces a single record for each CUSTOMER. Each output record needs to contain a count of the number of ORDERS of OrderType=1, a count of the number of ORDERS of OrderType=2, a count of the number of ORDERS of OrderType=3, etc. (for that CUSTOMER)
I know how to create this beast in MS-Access using the DCOUNT function, but I am using SQL Server here.
Any suggestions please?