loyola9988
New member
- Local time
- Yesterday, 21:55
- Joined
- Jun 21, 2018
- Messages
- 3
Hi,
I have a database which includes A column for Policy ID and a column for Payments. e.g.:
ID Payment
8006 400
8006 300
8006 400
8007 200
8007 100
8007 100
I need to find the mode on Payment column which is the most common amount for each policy. so end result would be
ID Payment
8006 400
8007 100
here is my query:
SELECT Count(*) AS RANK, AS400_Payments.ID, AS400_Payments.Amount AS Amount
FROM AS400_Payments
GROUP BY AS400_Payments.ID, AS400_Payments.Amount
ORDER BY Count(*) DESC;
but this show all payments with their frequencies not the most common one.
Please help!
Thanks very much in advance
I have a database which includes A column for Policy ID and a column for Payments. e.g.:
ID Payment
8006 400
8006 300
8006 400
8007 200
8007 100
8007 100
I need to find the mode on Payment column which is the most common amount for each policy. so end result would be
ID Payment
8006 400
8007 100
here is my query:
SELECT Count(*) AS RANK, AS400_Payments.ID, AS400_Payments.Amount AS Amount
FROM AS400_Payments
GROUP BY AS400_Payments.ID, AS400_Payments.Amount
ORDER BY Count(*) DESC;
but this show all payments with their frequencies not the most common one.
Please help!
Thanks very much in advance