Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Amanda_Nicholls
Starting Member
4 Posts |
Posted - 2012-01-25 : 16:50:28
|
| Ok I have done the followingSELECT DISTINCT tbl_Orders.CustomerID, tbl_Customer.CustSurname, tbl_Orders.QuantityFROM tbl_OrdersINNER JOIN tbl_CustomerON tbl_Orders.CustomerID=tbl_Customer.CustomerIDWHERE OrderDate<'2012-06-01'I have this as my output1 Swallow 11 Swallow 21 Swallow 202 Hunt 13 Bailey 13 Bailey 33 Bailey 104 Read 24 Read 54 Read 125 Blatt 15 Blatt 25 Blatt 67 Shelley 29 Jessey 1numbers on the left - Customer ID - then surname then quantityHow do I distinct them all so I just get the one customer ID with their surname and how many orders in total instead of the repetition?? beginner - bit stuck and could do with some help!Thanks everyone |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-25 : 16:56:08
|
| [code]SELECT tbl_Orders.CustomerID, tbl_Customer.CustSurname, SUM(tbl_Orders.Quantity) AS TotalQtyFROM tbl_OrdersINNER JOIN tbl_CustomerON tbl_Orders.CustomerID=tbl_Customer.CustomerIDWHERE OrderDate<'2012-06-01'GROUP BY tbl_Orders.CustomerID, tbl_Customer.CustSurname[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Amanda_Nicholls
Starting Member
4 Posts |
Posted - 2012-01-25 : 17:01:50
|
| Legend! Thank you! :) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 08:52:07
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|