First time poster hoping to get some assistance.
Very minimal coding experience so jargon may be confusing.
I am attempting to use SQL in Zoho to clean up data.
Data consists of A) Transactional Data (premium, fees, net earnings) per policy B) Claims Data (incurred amounts)
Issue is with the unique identifier - same client may have multiple policy numbers with either A) or B) not stored together. What I have been using is the systems own client code (different to policy number) which stores all the policy numbers under the same client. Second issue is Claims data is not mapped out to this 'client code'. Excel index/match/ vlookup have been my go tos in the meantime and has worked fine, however we are moving to Zoho which functions via SQL.
e.g.
| Client Code | Policy Number | Premium | Claims |
| -------- | -------------- | -------- | ------ |
| C1 | 123 | 500 | 300 |
| C2 | 456 | 100 | |
| C1 | 767 | 0 | | <---
| | 767 | | 800 | <--- want these columns put all under C1
Question: How can I Fill in the bottom left blank as C1 using SQL, and then Group each of the clients (C1 & C2) with a Total Premium & Claims amount for them?
GOAL:
| Client Code | Premium | Claims |
| -------- | --------- | ------ |
| C1 | 500 | 1100 |
| C2 | 100 | |
I've thought of using a Self Join -
SELECT
t1."Client Code",
t1."Policy Number",
t1."Premium",
t1."Claims",
t2."Client Code"
FROM table1 as t1
FULL OUTER JOIN
(SELECT
"Policy Number",
"Client Code"
FROM table1) t2
ON t1."Policy Number" = t2."Policy Number"
which clearly does not work, not to mention when I try to include sums by premium, I start receiving group by clause error messages.
Any help would be appreciated.
result:
t1.Client Code | t1.Policy Number | t1.Premium | t1.Claims | t2.Client Code |
---|---|---|---|---|
C1 | 123 | 500 | 300 | C1 |
C2 | 456 | 100 | C2 | |
C1 | 767 | 0 | C1 | |
C1 | 767 | 0 | ||
767 | 800 | C1 | ||
767 | 800 |
Other factors to consider which I've excluded: year of policy, further lines of transaction data due to monthly/ annual payments etc.