Home » RDBMS Server » Server Administration » How to use count function to count insurance policy which more than one person hold?
How to use count function to count insurance policy which more than one person hold? [message #373831] Mon, 14 May 2001 20:49 Go to next message
Steve
Messages: 190
Registered: September 1999
Senior Member
Hi,All:
How can I use count function to count insurance policy
which more than one person hold? (It means if more than
one person hold this policy, then I only need count this policy once)
Thanks
Steve
Re: How to use count function to count insurance policy which more than one person hold? [message #373833 is a reply to message #373831] Mon, 14 May 2001 21:51 Go to previous messageGo to next message
Sarada
Messages: 27
Registered: April 2001
Junior Member
Let's say your Insurance_policies table holds

POLICY_NO
POLICYHOLDER_NAME
AMOUNT_INSURED
...
Data
1 abc 100000
1 xyz 100000
2 def 50000
3 eee 150000

SELECT policy_no, COUNT(*)
FROM insurance_policies
GROUP BY policy_no
/

If this doesn't help you, post your table descriptions and we'll try to help u.

Orashark
Re: How to use count function to count insurance policy which more than one person hold? [message #373840 is a reply to message #373833] Tue, 15 May 2001 05:00 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
Or, if you want just the TOTAL number of policies, you can:

SELECT COUNT(DISTINCT(policy_number))
FROM insurance_table
GROUP BY policy_number;
Re: How to use count function to count insurance policy which more than one person hold? [message #373852 is a reply to message #373833] Tue, 15 May 2001 17:48 Go to previous message
Paul
Messages: 164
Registered: April 1999
Senior Member
The perils of trying to write SQL without being able to run it... leave out the GROUP BY clause and the result will be correct.
Previous Topic: Order By
Next Topic: How to query this question?
Goto Forum:
  


Current Time: Mon Jul 01 04:03:05 CDT 2024