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
 select count

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-08-23 : 15:05:24
I have a table that has two columns POLICY_NUMBER and POLICY_TYPE

POLICY_NUMBER POLICY-TYPE
123 1
123 1
123 1
567 2
567 2
789 1
789 1
345 1
345 1
345 1

I need to write a script that give me the following result

policy_type_count policy_type

3 1
1 1


James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-23 : 15:30:33
quote:
Originally posted by divan

I have a table that has two columns POLICY_NUMBER and POLICY_TYPE

POLICY_NUMBER POLICY-TYPE
123 1
123 1
123 1
567 2
567 2
789 1
789 1
345 1
345 1
345 1

I need to write a script that give me the following result

policy_type_count policy_type

3 1
1 1




SELECT 
COUNT(DISTINCT policy_number) AS policy_type_count,
[policy-type]
FROM
YourTable
GROUP BY
[policy-type]
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 2013-08-23 : 18:55:05
James you must have forgotten to include your script
Go to Top of Page
   

- Advertisement -