반응형
Claims Field Description
Claim_Number - Unique ID for insurance claim
Policy_Holder_Id - Unique ID for policy holder
Claim_Type - Indicator (Accident or Theft)
Claim_Amount - $$ amount of claim
Claim_Date_Filed - Date claim was filed
Claim_Date_Settle - Date claim was settled
Policyholders Field Description
PolicyHolderId - Unique ID for policy holder
YearEnrolled - Year policy holder enrolled in insurance
AnnualPremium - $$ amount policy holder pays yearly for coverage
Gender - Indicator (Male or Female)
Age - Age of policy holder
HomeDemo - Demographic of policy holder’s area of residence
a-1. How many claims has policy holder 405 made?
SELECT
CLAIM_NUMBER
FROM CLAIMS
WHERE POLICY_HOLDER_ID=405;
OR
SELECT COUNT(CLAIM_NUMBER) COUNTED
FROM CLAIMS
WHERE POLICY_HOLDER_ID=405;
a-2. What was the file date of the most recent claim that policy holder 405 has made?
SELECT CLAIM_DATE_FILED
FROM CLAIMS
WHERE POLICY_HOLDER_ID=405
ORDER BY CLAIM_DATE_FILED DESC;
a-3. What was the total amount of all claims filed by policy holder 405?
SELECT SUM(CLAIM_AMOUNT) TOTAL_AMOUNT
FROM CLAIMS
WHERE POLICY_HOLDER_ID=405;
b. What was the total claim amount and the average claim amount for accident claims by claim type?
Claim Type | Total Claim Amount | Average Claim Amount |
Accident | 2264503.66 | 9803.04 |
Theft | 481711.10 | 1926.84 |
SELECT SUM(CLAIM_AMOUNT) TOTAL_AMOUNT FROM CLAIMS WHERE CLAIM_TYPE="ACCIDENT";
SELECT AVG(CLAIM_AMOUNT) TOTAL_AMOUNT FROM CLAIMS WHERE CLAIM_TYPE="ACCIDENT";
SELECT SUM(CLAIM_AMOUNT) TOTAL_AMOUNT FROM CLAIMS WHERE CLAIM_TYPE="THEFT";
SELECT AVG(CLAIM_AMOUNT) TOTAL_AMOUNT FROM CLAIMS WHERE CLAIM_TYPE="THEFT";
C. DaysToSettle is a kpi that measures the number of days between the claim being filed and the claim being settled. What was the mean DaysToSettle for Accident claims vs. Theft claims?
select
avg(datediff(str_to_date(claim_date_settled, '%c/%d/%Y'),str_to_date(claim_date_filed, '%c/%d/%Y'))) AVG_GAP
from claims
where claim_type="theft";
select
avg(datediff(str_to_date(claim_date_settled, '%c/%d/%Y'),str_to_date(claim_date_filed, '%c/%d/%Y'))) AVG_GAP
from claims
where claim_type="accident";
D. How many policy holders in the policyholders table did not file any claims?
SELECT COUNT(POLICYHOLDERID) TOTAL FROM POLICYHOLDERS;
Total policyholder - 150
SELECT POLICY_HOLDER_ID TOTAL FROM CLAIMS GROUP BY POLICY_HOLDER_ID;
policyholder who filed claim - 118
반응형
'Database > SQL Server' 카테고리의 다른 글
MS SQL-사용자 지정 함수(스칼라, 인라인 테이블, 다중 테이블) (0) | 2020.12.04 |
---|---|
MS SQL Query 내장 함수(문자열, 숫자, 시간 관련 ) (0) | 2020.12.04 |
SQL Server-트리거 생성, ID 확인(Identity), 유니크 키 만들기, 조인 Join, having 과 where , stored procedure 프로시저 , 암호화(Encryption) (0) | 2020.12.03 |
MS SQL Server - 데이터베이스 생성/변경/삭제 , 테이블 생성/변경/삭제, 제약조건 생성 (0) | 2020.12.01 |
Session-데이터베이스(Database), SQL (0) | 2020.05.14 |