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 |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2006-07-23 : 07:52:04
|
| In a Order table, there are records like bellow:OrderID: 111,222,333 222, 222, 333How to code to count(OrderID) = 3 not = 6 ?I used code bellow but did not work:select count(OrderID) from Order group by OrderID |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-23 : 08:11:55
|
| This maybe?select count(DISTINCT OrderID) from OrderKristen |
 |
|
|
2400hrs
Starting Member
4 Posts |
Posted - 2006-07-23 : 08:15:52
|
| [code]SELECT COUNT(DISTINCT OrderID) FROM [Order][/code]Your SQL is counting the OrderIDs per grouping, so you will get something like:123If written [code] SELECT OrderID, COUNT(OrderID) OrderCount FROM [Order]GROUP BY OrderID[/code]You would see what it's doing:[code]Order ID OrderCount111 1222 3333 2[/code] |
 |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2006-07-23 : 09:22:16
|
| It works, thank both of you!!! |
 |
|
|
|
|
|