SQL
SQL
Table: BOOKS
Table: ISSUED
a)To show book name, author name and price of books of First Publ. Publisher:
Query: Select book_name, author_name, price from books where publisher=’First Publ’;
Output:
c) To display the names and price from books in descending order of their price.
Output:
Output:
e) To display the book_id, book name and QTY_issued for all books which have been issued.
Query: select book_ID, book_name, QTY_issued from books natural join issued;
Output:
f) To insert a new row in the table Issued having the following data: "F0003", 1.
Output:
g) Show the unique publisher name from books table of price more than 400.
Output:
h) Display the maximum price of books whose quantity is greater than 15.
a) To display Wno, Name, Gender from the table WORKER in descending order of Wno
Query: select wno, name, gender from worker order by wno desc;
Output:
b)To display the Name of all FEMALE workers from the table WORKER
Output:
c) To display the Wno and Name of those workers from the table WORKER who are born betweeb '1987-
01-01 and 1991-12-01.
Query: select wno,name from worker where dob between ‘1987-01-01’ and ‘1991-12-01’;
Output:
Output:
Output:
g)To display name, department city for all workers of worker number less than 1003.
Query: select name,department,city from dept natural join worker where wno<1003;
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
16) Suppose you have a sales table with colums product_id, category, and sales_amount, and you want
to find the total sales for each product category, but only for categories wit total sales greater than $500
Output:
4.Create table Teacher and admin and insert records in the table
Output:
b)TO display the names and subject of all female teachers
Query: select tname,subject from teacher natural join admin where gender='female';
Output:
c)To display the details of all teachers including gender and designation
Output:
Output:
Output:
Output:
c)To count the number of employees with names starting with ‘k’
Output:
d)to List names and addresses of those people who have ‘Delhi’ in their address
Query: select name, address from emp where address like ‘%Delhi’;
Output:
e)To list out all the employees whose salary is in between 70000 and 80000
Query: select name from emp where salary between 70000 and 80000;
Output:
Output:
g)To list out all the employee names whose phone number starts with ‘99’
Output:
h)To display all the details of employee whose salary is above 85000
Output:
i)To display all the employee names whose name contains the character ‘a’ anywhere
Output:
6. Write SQL commands for (a) to (i) on the basis of teacher relation given below
Table: Teacher1
Output:
b)To list the names of female teachers who are in maths department.
Query: Select name from teacher1 where sex='F' and department='maths';
Output:
c)To list names of all teachers with their date of joining in ascending order
Output:
d)To display teacher name, salary, age from male teachers only.
Query: select name, salary, age from teacher1 where sex= ‘M’;
Output:
e)To count the number of teachers with age>23.
Output:
f)To insert a new row in the TEACHER1 table with the following data:
Query: insert into teacher1 values(9, ‘Raja’, 26, ‘Computer’, ‘1995-05-13’, 2300, ‘M’);
Output:
Output:
h)Arrange the whole table in the alphabetical order to name.
Output:
i)Display the age of the teachers whose name starts with ‘S’.
Query: select name, age from teacher1 where name like ‘S%’;
Output:
7.
Table: Student1
Output:
b) List all the names of those students who are in class 12 sorted by stipend
Query: select name,stipend from student1 where class like '12%' order by stipend;
Output:
Output: