cs 12 assignment
cs 12 assignment
With reference to these tables, write commands in SQL for (i) and (ii) and output for (iii)
below.
(i) Display the PatNo, PatName, and corresponding DocName for each patient.
SELECT PatNo,PatName,DoName FROM patients, doctors WHERE patients
DocID=doctors.DocID;
(ii) Display the list of all patients whoseOPD_days are MWF.
(ii)-> select p.patho,p.patname,d.docname
-> from pateints p
-> join doctors d on p.docID = d.docID
-> where d.opd_days= ‘MWF’;
(iii) Display patient details of EnTand Ortho patients
Q3 Write SQL commands for statements (i) to (vi) and give output for SQL queries (vii) to (x)
on the basis of the table FAMILY:
(i) To display the name of all those where Male members are more than 3.
Ans: ->select name
->from family
-> where Male members>3;
(ii) To display the total female members of occupation business.
-> select sum ( FemaleMembers) as totalfemalemembers
-> from family
-> where Occupation = ‘business’;
(iii) To show the occupation of all those members whose income is between 75000 to
110000.
select name, occupation
-> from family
-> where income between 75000 and 110000;
(iv) To list the total no of female members which have an ‘o’ in their name.
select sum(femalemembers)as totalfemalememberswith0
-> from family
-> where name like’%o%’ and FemaleMembers> 0;
(v) To arrange the table in the descending order of income.
select*
-> from family
-> order by income DESC;
(vi)To insert a new record in the Family table with the following data:
9,’D’souza’,2,1,15000,’Service’.
-> INSERT INTO FAMILY (No, name, femalemembers, malemembers, income, occupation)
-> VALUES (9,’D’souza’,2,1,15000,’Service’);
(vii)SELECT MIN(DISTINCT Income) FROM Family;
c) Consider the table Flight given below, write command in SQL for (1) to (4) and output for
(5) to (8). Table : FLIGHT
f) Consider the table CARDEN and give the output of the following queries: Table: CARDEN
i) SELECT CarName FROM CARDEN where Color LIKE ‘%r’;
Q2. a) Write SQL Statement to create a table INVENTORY with the following structure:
Column ,Name ,Data Type Code- Decimal -4 ,Name -Varchar -15, Company- Varchar -15,
Price -Decimal-6, Quantity -Decimal- 4
b) Consider the following table and answer the following:
i. Identify the Primary key and the candidate key in the above table.
ii. Write MySQL query to add a column Diagnosis with data type Varchar and size 35 in the
table Patient.
c) Consider the table GARMENTS with the following data and answer the question that
follows:-
iii. Display the Category and price of all the products manufactured by Peter England.
iv. Increase the price of the entire Category by 5%.
v. Add a new record with following data values: ‘TS421’, ‘T-Shirt’, NULL, 1000, ‘2012-05-20’