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 |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-04-23 : 03:10:54
|
how can i exclude the ID to be get the same counttotal ID 10ID 111 purchase itemA and itemBID 222 purchase itemCID 333 purchase itemDi tried select COUNT(*),item from tableA group by itembut it return the total of 11Total Item1 itemA1 itemB1 itemC1 itemD7 NULL |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-23 : 03:15:06
|
means it is grouping NULLs as one group... right?Include SELECT COUNT(*), itemFROM tableAWHERE item IS NOT NULLGROUP BY item--Chandu |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-04-23 : 03:19:12
|
the result should be as belowTotal Item1 itemA1 itemB1 itemC1 itemD6 NULL |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-23 : 03:33:46
|
Can you post sample data and respective output for that data?--Chandu |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-04-23 : 03:45:05
|
i have list of data as belowtotal ID = 10ID 111 purchase itemA and itemBID 222 purchase itemCID 333 purchase itemDID 444 purchase noneID 555 purchase noneID 666 purchase noneID 777 purchase noneID 888 purchase noneID 999 purchase noneID 100 purchase nonei would like to group them up. but total should be 10.select COUNT(*),item from tableA group by itembut it return the total of 11 as below:Total Item1 itemA1 itemB1 itemC1 itemD7 NULLResult should be as below:Total Item1 itemA1 itemB1 itemC1 itemD6 NULL |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-23 : 04:21:51
|
how come total of NULL group 6? there are 7 IDs with Item=noneUnder ID=111 there is two items( A and B).. so total count is 11--Chandu |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-04-23 : 04:35:30
|
because it shared the same ID. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-23 : 05:06:55
|
See the following groups... Your query will group and then counts Number of IDs like this:ItemA------ID 111 Total = 1ItemB------ID 111 Total = 1ItemC------ID 222 Total = 1ItemD------ID 333 Total = 1NULL (none)------ID 444 purchase noneID 555 purchase noneID 666 purchase noneID 777 purchase noneID 888 purchase noneID 999 purchase noneID 100 purchase noneTotal = 7--Chandu |
|
|
|
|
|