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
 count two variables

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-08-23 : 20:24:36
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 2

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-08-23 : 20:41:39
James K responded to your post: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=187749
with the following query, it should give you what you want:
[CODE]

SELECT
COUNT(DISTINCT policy_number) AS policy_type_count,
[policy-type]
FROM
YourTable
GROUP BY
[policy-type]

[/CODE]
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 2013-08-23 : 20:53:15
But I do not see the query
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-08-23 : 21:47:34
quote:
Originally posted by divan

But I do not see the query


Do you see this one:
[CODE]
SELECT
COUNT(DISTINCT policy_number) AS policy_type_count,
[policy-type]
FROM
YourTable
GROUP BY
[policy-type]





[/CODE]
Go to Top of Page
   

- Advertisement -