0% found this document useful (0 votes)
3 views11 pages

Dbms Assignment 4

The document contains a series of SQL queries related to hospital and staff management, including creating tables and inserting data. It includes queries to find hospitals in New York with charges over 20,000, create views for hospitals in Paris, and match staff with hospitals based on ward IDs. Each question is followed by the corresponding SQL solution, demonstrating various database operations.

Uploaded by

devx.ankitx
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)
3 views11 pages

Dbms Assignment 4

The document contains a series of SQL queries related to hospital and staff management, including creating tables and inserting data. It includes queries to find hospitals in New York with charges over 20,000, create views for hospitals in Paris, and match staff with hospitals based on ward IDs. Each question is followed by the corresponding SQL solution, demonstrating various database operations.

Uploaded by

devx.ankitx
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/ 11

DBMS LAB VIEW

Question-1: - Write a query to find the hospital of the city New York who obtained the charges
greater than 20,000.

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES

(101,"Liam","New York"," [email protected] ",20000),

(102," Noah "," Paris "," [email protected] ",30000),

(103," William "," Paris "," [email protected] ",40000),

(104," James "," Rome "," [email protected] ",50000),

(105," Oliver ","New York"," [email protected] ",70000);


Question-2: - Write a query to create a view that shows each hospital with more than one doctor.

Solution-2: -

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES

(101,"Liam","New York"," [email protected] ",20000),

(102," Noah "," Paris "," [email protected] ",30000),

(103," William "," Paris "," [email protected] ",40000),

(104," James "," Rome "," [email protected] ",50000),

(105," Oliver ","New York"," [email protected] ",70000);

CREATE TABLE Doctor

DoctorID INT ,
WardID Int,

title CHAR(7),

firstname CHAR(20),

Lastname CHAR(40) NOT NULL,

Code CHAR(5),

address CHAR(40)

);

INSERT INTO Doctor VALUES (110,101,'Mrs','Jenny','Porter','10580','1340 N. Ash Street, #3'),

(120,101,'Mr','Peter','Brown','48226','1001 34th St., APT.3'),

(150,104,'Company',NULL,'Datasoft','90018','486 Maple St.'),

(130,104,'Mrs','Rose','Brian','75243','500 Yellowstone Drive, #2'),

(130,104,'Mrs','Mary','Griffith','20005','3401 Elder Lane'),

(140,104,'Mr','Martin',' Randolph','60615','340 MAIN STREET, #7'),

(140,103,'Mrs','Sally','Smith','75243','250 Curtis Street'),

(70,103,'Mr','Mike','Jackson','45211', '133 BROADWAY APT. 1'),

(70,102,'Mrs','Rita','Doe','97213', '2000 Humboldt St., #6'),

(70,102,'Mr','George','Howe','75243', '111 B Parkway, #23'),

(80,103,'Mr','Frank','Miller','95054','27 5th St., 76');


Question-3: - Write a query to create a view for those hospital belongs to the city Paris.

Solution-3: -

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES

(101,"Liam","New York"," [email protected] ",20000),

(102,"Noah","Paris"," [email protected] ",30000),

(103,"William","Paris"," [email protected] ",40000),

(104,"James","Rome"," [email protected] ",50000),

(105,"Oliver","New York"," [email protected] ",70000);


Question-4: -

Write a query to create a view for all hospital record with columns ward id, patient name and city.

Solution-4: -

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES

(101,"Liam","New York"," [email protected] ",20000),

(102,"Noah","Paris"," [email protected] ",30000),

(103,"William","Paris"," [email protected] ",40000),

(104,"James","Rome"," [email protected] ",50000),

(105,"Oliver","New York"," [email protected] ",70000);


Question-5: - Write a query to create a view that find the staff details whose joining date either 19-
april-91 or 1-may-91.

Solution-5: -

create table staff

(staff_id int (10) not null,

staff_name varchar (40) not null,

staff_age int (5) not null,

staff_salary int(15) not null,

joining_date varchar (15) not null,

WardID int,

DoctorID INT

);

insert into staff values

(1001,'Asad',20,20000,'13-july-91',101,110),

(1002,'qayyum',23,40000,'13-july-90',102,110),

(1003,'hassan',25,70000,'13-feb-92',102,120),

(1004,'amin',27,35000,'1-may-91',103,120),

(1005,'atiq khan',21,38000,'19-april-92',104,130),
(1006,'juniad',25,29000,'28-may-90',104,130),

(1007,'asif hussain',24,19000,'19-april-91',105,150),

(1008,'kashif ktk',45,90000,'1-sep-93',102,150),

(1009,'bahadur khan',37,89000,'20-sep-92',101,130),

(1100,'bilal',34,29000,'1-may-91',104,140);

Question-6: - Write a query to create a view that finds the hospital whose staff joining date on 1-
may-91.

Solution-6: -

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES


(101,"Liam","New York"," [email protected] ",20000),

(102," Noah "," Paris "," [email protected] ",30000),

(103," William "," Paris "," [email protected] ",40000),

(104," James "," Rome "," [email protected] ",50000),

(105," Oliver ","New York"," [email protected] ",70000);

create table staff

(staff_id int (10) not null,

staff_name varchar (40) not null,

staff_age int (5) not null,

staff_salary int(15) not null,

joining_date varchar (15) not null,

WardID int,

DoctorID INT

);

insert into staff values

(1001,'Asad',20,20000,'13-july-91',101,110),

(1002,'qayyum',23,40000,'13-july-90',102,110),

(1003,'hassan',25,70000,'13-feb-92',102,120),

(1004,'amin',27,35000,'1-may-91',103,120),

(1005,'atiq khan',21,38000,'19-april-92',104,130),

(1006,'juniad',25,29000,'28-may-90',104,130),

(1007,'asif hussain',24,19000,'19-april-91',105,150),

(1008,'kashif ktk',45,90000,'1-sep-93',102,150),

(1009,'bahadur khan',37,89000,'20-sep-92',101,130),

(1100,'bilal',34,29000,'1-may-91',104,140);
Question-7: - Write a query to create a view that shows all matches of staff with hospital where at
least one staff in the assigned one wardID of hospital served by a staff in the ward of the hospital.

Solution-7: -

CREATE TABLE Hospital

WardID int,

PaitentsName varchar(50),

City varchar(50),

Emailid varchar(50),

Charges Integer

);

INSERT INTO Hospital (WardID,PaitentsName, City, Emailid, Charges) VALUES

(101,"Liam","New York"," [email protected] ",20000),

(102," Noah "," Paris "," [email protected] ",30000),

(103," William "," Paris "," [email protected] ",40000),

(104," James "," Rome "," [email protected] ",50000),

(105," Oliver ","New York"," [email protected] ",70000);


create table staff

(staff_id int (10) not null,

staff_name varchar (40) not null,

staff_age int (5) not null,

staff_salary int(15) not null,

joining_date varchar (15) not null,

WardID int,

DoctorID INT

);

insert into staff values

(1001,'Asad',20,20000,'13-july-91',102,110),

(1002,'qayyum',23,40000,'13-july-90',102,110),

(1003,'hassan',25,70000,'13-feb-92',102,120),

(1004,'amin',27,35000,'1-may-91',103,120),

(1005,'atiq khan',21,38000,'19-april-92',104,130),

(1006,'juniad',25,29000,'28-may-90',104,130),

(1007,'asif hussain',24,19000,'19-april-91',105,150),

(1008,'kashif ktk',45,90000,'1-sep-93',102,150),

(1009,'bahadur khan',37,89000,'20-sep-92',102,130),

(1100,'bilal',34,29000,'1-may-91',104,140);

You might also like