Knowee
Questions
Features
Study Tools

Using the following schema, write SQL statement to fetch the correct data.Insurance_Company (c_id, c_name, city, state, policy_no, policy_name, premium, cust_id, a_id)Agent (a_id, a_name, address, a_city, a_state, c_name, salary, incentive)Customer (cust_id, name, age, cust_address, cust_city, cust_state, a_id, policy_no)Create tables with Primary Key, foreign key constraints in given schemas.1) Display the details of customer who have taken policy from ‘Ahmedabad Insurance Company’.2) Display agent name who have not sold even a single policy.3) Display the name of Insurance company who has maximum number of customers

Question

Using the following schema, write SQL statement to fetch the correct data.Insurance_Company (c_id, c_name, city, state, policy_no, policy_name, premium, cust_id, a_id)Agent (a_id, a_name, address, a_city, a_state, c_name, salary, incentive)Customer (cust_id, name, age, cust_address, cust_city, cust_state, a_id, policy_no)Create tables with Primary Key, foreign key constraints in given schemas.1) Display the details of customer who have taken policy from ‘Ahmedabad Insurance Company’.2) Display agent name who have not sold even a single policy.3) Display the name of Insurance company who has maximum number of customers

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here are the SQL statements for each of the tasks:

  1. To create the tables with Primary Key, foreign key constraints in given schemas:
CREATE TABLE Insurance_Company (
    c_id INT PRIMARY KEY,
    c_name VARCHAR(255),
    city VARCHAR(255),
    state VARCHAR(255),
    policy_no INT,
    policy_name VARCHAR(255),
    premium DECIMAL(10, 2),
    cust_id INT,
    a_id INT
);

CREATE TABLE Agent (
    a_id INT PRIMARY KEY,
    a_name VARCHAR(255),
    address VARCHAR(255),
    a_city VARCHAR(255),
    a_state VARCHAR(255),
    c_name VARCHAR(255),
    salary DECIMAL(10, 2),
    incentive DECIMAL(10, 2)
);

CREATE TABLE Customer (
    cust_id INT PRIMARY KEY,
    name VARCHAR(255),
    age INT,
    cust_address VARCHAR(255),
    cust_city VARCHAR(255),
    cust_state VARCHAR(255),
    a_id INT,
    policy_no INT,
    FOREIGN KEY (a_id) REFERENCES Agent(a_id),
    FOREIGN KEY (policy_no) REFERENCES Insurance_Company(policy_no)
);
  1. To display the details of customer who have taken policy from ‘Ahmedabad Insurance Company’:
SELECT * 
FROM Customer 
JOIN Insurance_Company ON Customer.policy_no = Insurance_Company.policy_no 
WHERE Insurance_Company.c_name = 'Ahmedabad Insurance Company';
  1. To display agent name who have not sold even a single policy:
SELECT a_name 
FROM Agent 
LEFT JOIN Insurance_Company ON Agent.a_id = Insurance_Company.a_id 
WHERE Insurance_Company.policy_no IS NULL;
  1. To display the name of Insurance company who has maximum number of customers:
SELECT c_name 
FROM Insurance_Company 
JOIN Customer ON Insurance_Company.cust_id = Customer.cust_id 
GROUP BY c_name 
ORDER BY COUNT(*) DESC 
LIMIT 1;

Please note that these SQL statements are written assuming that the database is following the schema provided in the question. If the schema is different, these statements may need to be adjusted.

This problem has been solved

Similar Questions

Consider following schema and write query for given statementEmp (eid,ename,city,dname,salary) Project(eid,pid,pname,location)Create tables with Primary Key, foreign key constraints in given schemas.(1) Display name of employees who belongs to Computer department.(2) Display employee id whose name starts from letter J.(3) Display all details of employees whose salary is from 10000 to 20000.(4) Display name of employees who are having maximum salary.(5) Display name of employees whose salary is higher than average salary of the employee.(6) Display name of employees whose project id is 3 and location is Mumbai

Use the Simple Query Wizard to create a select query combining fields from two related tables. Include these fields in this order: LastName, FirstName, and MedicalInsurance fields from the Staff table and the Premium field from the InsurancePlans table. Include every record in the results. Select the option to open the query to view information. Name the query Insurance and view the query results.

i. Create a database called orderproc_db for an Order processing company usingMySQL.ii. Replace the data types in the tables given below with MySQL Compatible format.iii. Using the orderproc_db database, create the following tables.CUSTOMER (custno: INT, cname: STRING, city: STRING)ORDE (orderno: INT, odate: DATE, custno: INT, ord_amt: INT)ITEM (itemno: INT, unit_price: INT)ORDE_ITEM (orderno: INT, itemno: INT, qty: INT)WAREHOUSE (warehouseno: INT, city: STRING)SHIPMENT (orderno: INT, warehouseno: INT, ship_date: DATE)iv. Identify the primary key and define primary key constrains for the table.v. Identify the foreign keys and enforce referential integrity for the tables.vi. Describe the structures of the tables you have created above.vii. Insert the records to the tables. Records are available as text files with the respectivetable names in a folder called “Tables” on your desktop. You need to properly formatthese records before inserting into the tables.viii. List all customers from Batticaloa.ix. Propose an alternative method to execute the above question (viii).x. Select all customers who are from Batticaloa or Jaffna.xi. How many customers are there in Colombo?xii. List the customer’s name ending with the letters “na”.xiii. List all the order amount above 50000.xiv. List all customers name who made order above 50000.xv. List all customers name who have at least one warehouse in their city.xvi. How many different cities are there in the customer table.xvii. How many warehouses are there in Colombo?.xviii. How do you check all order dates are less than or equal to shipping dates?xix. List all the order number, order date, customer number and order amount where all theshipment made from Colombo warehouses.

Consider following schema and write SQL for given statements.worker (id,firstname,lastname,salary,joining_date,dept)bonus(id,bonus_date,amount)1. Find firstname and lastname of worker whose amount is greater than 2400.2. List out salary of worker with id who got bonus

Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.