write the SQL commands on the basis of table
HOSPITAL.
TABLE: HOSPITAL
(A) To show all information about the patients of cardiology
department.
Ans: SELECT * FROM hospital WHERE department='Cardiology;
(B) To list the names of female patients who are in orthopedic dept.
Ans: SELECT name FROM hospital WHERE sex='F° AND
department='Orthopedic;
(C) To list names of all patients with their date of admission in
ascending order.
Ans.: SELECT name, datofadm FROM hospital ORDER BY
datofadm;
(D) To display Patient's Name, Charges, age for male patients only.
Ans: SELECT name, charges, age FROM hospital WHERE
sex='M';
(E) To count the number of patients with age >20.
Ans.: SELECT COUNT(age) FROM hospital WHERE age>20;
Assume that there is one more table GUIDE in the
database as shown below:
What will be the output of the following query:
SELECT NAME, ADVISOR FROM GRADUATE, GUIDE WHERE
SUBJECT=MAINAREA;
Ans.:
NAME ADVISOR
Karan Vinod
Divakar Alok
Divya Rajan
Arun Vinod
Sabina Mahesh
John Rajan
Robert Vinod
Rubina Mahesh
Vikas Alok
Mohan Rajan
Write SQL commands on the basis of table GRADUATE.
(A) List the names of those students who obtained DIV
1 sorted by NAME.
Ans.: SELECT name FROM graduate WHERE div=1
ORDER BY name;
(B) Display a report, listing NAME, STIPEND, SUBJCT
and amount of stipend received in a year assuming that
the STIPEND is paid every month.
Ans.: SELECT name, stipend, subject, stipend *12
FROM graduate;
(C) To insert a new row in the GRADUATE table :
11, KAJOL»,300," COMPUTERS»,75,1
Ans.: INSERT INTO graduate VALUES (11, 'Kajol', 300,
'Computers', 75,1);
Write the output on the basis of given table:
Output:-
(i) Select COUNT(distinct TYPE) from INTERIORS;
Ans.: COUNT(DISTICNT TYPE)
5
(ii) Select AVG(DISCOUNT) from INTERIORS where
TYPE = " Baby Cot";
Ans.: AVG (DISCOUNT)
13
(iii) Select SUM(Price) from INTERIORS where
DATOFSTOCK < ( 12/02/02);
Ans.: SUM(PRICE)
53000
Write the output on the basis of given
table
Output:-
(i) Select COUNT(distinct TYPE) from INTERIORS;
Ans.: COUNT(DISTICNTTYPE)
5
(ii) Select AVG(DISCOUNT) from INTERIORS where
TYPE = " Baby Cot";
Ans.: AVG(DISCOUNT)
13
(iii) Select SUM(Price) from INTERIORS where
DATOFSTOCK < ( 12/02/02};
Ans.: SUM(PRICE) 53000