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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to find the count from multiple column

Author  Topic 

pankaj2910
Starting Member

31 Posts

Posted - 2014-03-24 : 14:02:57
let us suppose

ID | companycode | year | name | State
1 | 01 | 2013 | xyz | D
1 | 01 | 2013 |abs | S
23| 02 | 2014 | age | D
2 | 01 | 2013 | XYZ | D
1 | 01 | 2013 | abh | D
7 | 13 | 2014 | adi | C
7 | 13 | 2014 | adi | C
7 | 13 | 2013 | adi | C
7 | 13 | 2014 | adi | C
7 | 13 | 2013 | adp | C
7 | 13 | 2014 | abp | C

and we want like this

ID | companycode | year | countname | State
1 | 01 | 2013 | 2 | D
23| 02 | 2014 | 1 | D
1 | 01 | 2013 | 1 | s
2 | 01 | 2013 | 1 | D
7 | 13 | 2013 | 2 | C
7 | 13 | 2014 | 4 | c

pankajrocks

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-03-24 : 18:46:18
[CODE]select
ID, companycode, year, count(*) countname, State
from
MyTable
group by
ID, companycode, year, State[/CODE]

===============================================================================
“Everyone wants a better life: very few of us want to be better people.”
-Alain de Botton
Go to Top of Page

pankaj2910
Starting Member

31 Posts

Posted - 2014-03-25 : 00:53:16
Sorry I want

ID | companycode | year | countname | State
1 | 01 | 2013 | 2 | D
23| 02 | 2014 | 1 | D
1 | 01 | 2013 | 1 | s
2 | 01 | 2013 | 1 | D
7 | 13 | 2013 | 2 | C
7 | 13 | 2014 | 2 | c

as result

pankajrocks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-25 : 01:05:15
you want this ?
count ( distinct name )



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pankaj2910
Starting Member

31 Posts

Posted - 2014-03-25 : 02:12:14
yes
but year wise

pankajrocks
Go to Top of Page
   

- Advertisement -