newsqluser02
Technical User
I am new to SQL and trying to find a more effective way to accomplish what I'm doing.
So I am trying to find patterns for the errors in my data. I have several fields that can determine if these errors exist.
Here are the fields that I have in my database
I am wanting group the data by company_code first and then see if one said company_code has more premium_rate_variance that has values "Yes" than values "No".
If this is not the case, break the grouping down further into company_code and deal_id. Then check which premium_rate_variance has more "Yes" than "No"
And continue breaking it down until it has sorted it out completely.
I know this is very basic, because to truly see patterns, I'd have to start with run each of the fields seperate, then run two fields, then three, etc.
I have written some code, though I know it is wrong but it shows where I am going:
So I am trying to find patterns for the errors in my data. I have several fields that can determine if these errors exist.
Here are the fields that I have in my database
Code:
company_code, deal_id, sex_code, unisex, issue_age, level_term_period, underwriting_class, rider_code, table_rating, policy_year, band, face_amount, premium_rate, calculated_premium_rate, premium_rate_variance
I am wanting group the data by company_code first and then see if one said company_code has more premium_rate_variance that has values "Yes" than values "No".
If this is not the case, break the grouping down further into company_code and deal_id. Then check which premium_rate_variance has more "Yes" than "No"
And continue breaking it down until it has sorted it out completely.
I know this is very basic, because to truly see patterns, I'd have to start with run each of the fields seperate, then run two fields, then three, etc.
I have written some code, though I know it is wrong but it shows where I am going:
Code:
IF
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code)
select * from treaty_validation_data
where (select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code)
group by company_code
ELSE
IF
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code, deal_id)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code, deal_id)
select * from treaty_validation_data
where (select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code, deal_id)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code, deal_id)
group by company_code, deal_id
ELSE
IF
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code, deal_id, sex_code)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code, deal_id, sex_code)
select * from treaty_validation_data
where (select count(company_code) from treaty_validation_data where premium_rate_variance = 'Y' group by company_code, deal_id, sex_code)
>
(select count(company_code) from treaty_validation_data where premium_rate_variance = 'N' group by company_code, deal_id, sex_code)
group by company_code, deal_id, sex_code