0% found this document useful (0 votes)
361 views

4 Mysql Ims Casestudy

The document contains the SQL queries to create database, tables, insert sample data and queries to retrieve data from the tables. The tables created are address_details, user_details, ref_policy_types, policy_sub_types, user_policies and policy_payments. Sample data is inserted into these tables. 21 queries are listed to retrieve data from these tables by joining multiple tables.

Uploaded by

Sachin Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
361 views

4 Mysql Ims Casestudy

The document contains the SQL queries to create database, tables, insert sample data and queries to retrieve data from the tables. The tables created are address_details, user_details, ref_policy_types, policy_sub_types, user_policies and policy_payments. Sample data is inserted into these tables. 21 queries are listed to retrieve data from these tables by joining multiple tables.

Uploaded by

Sachin Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DDL Queries:

create database insurancedb;

use insurancedb

create table address_details(address_id int primary key,h_no varchar(6),city varchar(50),addressline1 varchar(50),state


varchar(50),pin varchar(50));

create table user_details(user_id int primary key,firstname varchar(50),lastname varchar(50),email varchar(50),mobileno


varchar(50),address_id int references address_details(address_id),dob date);

create table ref_policy_types(policy_type_code varchar(10) primary key,policy_type_name varchar(50));

create table policy_sub_types(policy_type_id varchar(10) primary key,policy_type_code varchar(10) references


ref_policy_types(policy_type_code),description varchar(50),yearsofpayements int,amount double,maturityperiod
int,maturityamount double,validity int);

create table user_policies(policy_no varchar(20) primary key,user_id int references user_details(user_id),date_registered


date,policy_type_id varchar(10) references policy_sub_types(policy_type_id) );

create table policy_payments(receipno int primary key,user_id int references user_details(user_id),policy_no varchar(20)
references user_policies(policy_no),dateofpayment date,amount double,fine double);

DML QUERIES:

insert into address_details values(1,'6-21','hyderabad','kphb','andhrapradesh',1254);

insert into address_details values(2,'7-81','chennai','seruseri','tamilnadu',16354);

insert into address_details values(3,'3-71','lucknow','street','uttarpradesh',86451);

insert into address_details values(4,'4-81','mumbai','iroli','maharashtra',51246);

insert into address_details values(5,'5-81','bangalore','mgroad','karnataka',125465);

insert into address_details values(6,'6-81','ahamadabad','street2','gujarat',125423);

insert into address_details values(7,'9-21','chennai','sholinganur','tamilnadu',654286);


insert into user_details values(1111,'raju','reddy','[email protected]','9854261456',4,'1986-4-11');

insert into user_details values(2222,'vamsi','krishna','[email protected]','9854261463',1,'1990-4-11');

insert into user_details values(3333,'naveen','reddy','[email protected]','9854261496',4,'1985-3-14');

insert into user_details values(4444,'raghava','rao','[email protected]','9854261412',4,'1985-9-21');

insert into user_details values(5555,'harsha','vardhan','[email protected]','9854261445',4,'1992-10-11');

insert into ref_policy_types values('58934','car');

insert into ref_policy_types values('58539','home');

insert into ref_policy_types values('58683','life');

insert into policy_sub_types values('6893','58934','theft',1,5000,null,200000,1);

insert into policy_sub_types values('6894','58934','accident',1,20000,null,200000,3);

insert into policy_sub_types values('6895','58539','fire',1,50000,null,500000,3);

insert into policy_sub_types values('6896','58683','anandhlife',7,50000,15,1500000,null);

insert into policy_sub_types values('6897','58683','sukhlife',10,5000,13,300000,null);

insert into user_policies values('689314',1111,'1994-4-18','6896');

insert into user_policies values('689316',1111,'2012-5-18','6895');

insert into user_policies values('689317',1111,'2012-6-20','6894');

insert into user_policies values('689318',2222,'2012-6-21','6894');

insert into user_policies values('689320',3333,'2012-6-18','6894');

insert into user_policies values('689420',4444,'2012-4-09','6896');

insert into policy_payments values(121,4444,'689420','2012-4-09',50000,null);

insert into policy_payments values(345,4444,'689420','2013-4-09',50000,null);


insert into policy_payments values(300,1111,'689317','2012-6-20',20000,null);

insert into policy_payments values(225,1111,'689316','2012-5-18',20000,null);

insert into policy_payments values(227,1111,'689314','1994-4-18',50000,null);

insert into policy_payments values(100,1111,'689314','1995-4-10',50000,null);

insert into policy_payments values(128,1111,'689314','1996-4-11',50000,null);

insert into policy_payments values(96,1111,'689314','1997-4-18',50000,200);

insert into policy_payments values(101,1111,'689314','1998-4-09',50000,null);

insert into policy_payments values(105,1111,'689314','1999-4-08',50000,null);

insert into policy_payments values(120,1111,'689314','2000-4-05',50000,null);

insert into policy_payments values(367,2222,'689318','2012-6-21',20000,null);

insert into policy_payments values(298,3333,'689320','2012-6-18',20000,null);

Solve the following Queries:

1. Write a query to display the policytypeid,policytypename,description of all the cars policy


details.
2. Write a query to display the policytypecode,no of polycies in each code with alias name
NO_OF_POLICIES.
3. Write a query to display the userid,firstname,lastname, email,mobileno who are residing in
Chennai.
4. Write a query to display the userid, firstname lastname with alias name
USER_NAME,email,mobileno who has taken the car polycies.
5. Write a query to display the userid, firstname,last name who has taken the car policies but not
home ploicies.
6. Write a query to display the policytypecode, policytype name which policytype has maximum
no of policies.
7. Write a query to display the userid, firtsname, lastname, city state whose city is ending with
bad.
8. Write a query to display the userid, firstname, lastname ,ploicyno, dateregistered who has
registered before may 2012.
9. Write a query to display the userid, firstname, lastname who has taken more than one policies.
10. Write a query to display the policytypecode, policytypename, policytypeid, userid, ploicyno
whose maturity will fall in the month of august 2013.
11. Write a query to display the policytypecode, policytypename, policytypeid whose maturity
amount is the double than the total paid amount.
12. Write a query to display the userid, total amount paid by the customer with alias name
total_amount.
13. Write a query to display the user_id, policy_no, total amount paid by the customer for the each
policies.
14. Write a query to display the user_id, policy_no, balance_amount for each policies.
15. write a query to display the user_id,policy_no, balancepayment years with alias name
BALANCE_YEARS for all the customer for each policies.
16. Write a query to display the user details userid,firstname,last who has taken car, home and life
loans.
17. Write a query to select policy_type_code,total amount paid by all the customers with alias
name total_amount for each policy department.
18. Write a query to select user_id,user_name,policy_type_code,policy_type_id of users who has
registered more than one policy type unde same policy code.
19. Write a query to display the policy_type_code,policytype name in which policy department has
min number of policies registered.
20. Write a query to display the user_id,user_name,
address,phoneno,policytypecode,policytypeid,policytypename, who has complemented all
payements for the policies.
21. write a query to display the user_id, user_name,
address,phoneno,policytypecode,policytypeid,policytypename,date ofd register who has
registered latest 2.

You might also like