0% found this document useful (0 votes)
34 views

SQL Programs

The document describes creating tables to store electricity bill, student, employee, and bank data. It provides SQL statements to: 1. Insert data into the tables 2. Add, update, and compute fields in the tables 3. Join tables and retrieve selected records based on conditions A variety of SQL commands like CREATE TABLE, INSERT, SELECT, UPDATE, ALTER TABLE are used to generate test data and perform calculations on the fields to generate results like electricity bills, student results, employee salaries etc. Joins are made between related tables to retrieve relevant information.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

SQL Programs

The document describes creating tables to store electricity bill, student, employee, and bank data. It provides SQL statements to: 1. Insert data into the tables 2. Add, update, and compute fields in the tables 3. Join tables and retrieve selected records based on conditions A variety of SQL commands like CREATE TABLE, INSERT, SELECT, UPDATE, ALTER TABLE are used to generate test data and perform calculations on the fields to generate results like electricity bills, student results, employee salaries etc. Joins are made between related tables to retrieve relevant information.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL Problem NO – 1

Generate the Electricity Bill for one consumer.


Create a table for household Electricity bill with the following fields

Field name Type


RR_number Varchar2(10)
Consumer_name Varchar2(25)
Date_billing Date
Units Number(4)

1. Insert 10 records into the table.


2. Check the structure of table
3. Add 2 new fields to the table
 Bill_amt number(6,2)
 Due_date date(8)
4. Compute the bill amount for each customer as per the following rules
Min_amt Rs.50
First 100 units Rs. 4.50/unit
>100 units Rs. 5.50/unit
5. Compute due_date as billing_date+15 days
6. List all the bills generated

1. create table ele (RRno varchar(10), name char(25), billdate date, units int(4));

2. insert into ele values(‘a1’,’anu’,’2022/11/10’,35);


insert into ele values(‘a2’,’manu’,’2022/9/10’,135);
insert into ele values(‘a3’,’tanu’,’2022/10/10’,145);
insert into ele values(‘a4’,’sonu’, ’2022/1/10’,55);
insert into ele values(‘a5’,’ramu’,’2022/8/10’,65);
insert into ele values(‘a6’,’gana’,’2022/9/10’,151);
insert into ele values(‘a7’,’gayana’,’2022/11/10’,30);
insert into ele values(‘a8’,’suma’,’2022/10/10’,150);
insert into ele values(‘a9’,’uma’,’2022/5/10’,35);
insert into ele values(‘a10’,’soma’,’2022/10/10’,35);

3. desc ele;
4. alter table ele add(billamt decimal, duedate date);
5. select * from ele;
6. update ele Set billamt=50+units*4.50 where units<=100;
7. update ele set billamt=50+100*4.50+(units-100)*5.50 where units>100;
8. update ele Set duedate=billdate+15;
9. select * from ele;
SQL Problem No .2

Create a student database and compute the result.

Create a table for a class of students with the following details

Name type
Std_id Number(2)
Std_name Varchar2(10)
Sub1_marks Number(2)
Sub2_marks Number(2)
Sub3_marks Number(2)
Sub4_marks Number(2)
Sub5_marks Number(2)
Sub6_marks Number(2)

1. Add records into the table for 10 students for std_id, std_name and 6 subject marks using insert
command

2. Display the description of the fields in the table using desc command

3. Alter the table and calculate total and percentage

4. Compute the result as “pass” or “fail” by checking if the student has scored more than 35 marks in
each subject

5. List the contents of the table

6. Retrieve all the records of the table

1. create table std (Id int(4), Name char(10),S1 int(2),S2 int (2),S3 int(2), S4 int(2) ,S5 int(2),S6 int(2));

2. insert into std values(1,’anu’,70,80,60,50,45,23);


insert into std values(2,’sonu’,55,23,90,56,45,45);
insert into std values(3,’manu’,35,75,50,56,55,78);
insert into std values(4,’suma’,55,65,87,56,45,63);
insert into std values(5,’uma’,25,65,90,56,54,65);
insert into std values(6,’seema’,55,76,90,56,45,65);
insert into std values(7,’sowmya’,55,76,87,56,54,76);
insert into std values(8,’ramesh’,37,46,90,56,45,46);
insert into std values(9,’mahesh’,37,46,90,56,45,35);
insert into std values(10,’ramu’,37,35,87,56,54,34);
3. desc std;

4. alter table std add(tot int(3),per decimal(3,1),res char(4));

5. update std set tot=s1+s2+s3+s4+s5+s6;

6. update std set per=tot/6;

7. update std set res=’pass’ where (s1>=35 and s2>=35 and s3>=35 and s4>=35 and s5>=35 and
s6>=35);

8. update std set res=’fail’ where (s1<35 or s2<35 or s3<35 or s4<35 or s5<35 or s6<35);

9. select * from std;

10. select Id, Name from std;

11. select * from std where res =’pass’;

12. select * from std where res=’fail’;

13. select count(*) from std where res=’pass’;

14. select count(*) from std where res=’fail’;

15. select * from std where per >60;

16. select * from std order by Id;


SQL Problem No .3
Generate the Employee details and compute the salary based on the department.

Create the following table employee

Field name Datatype

Emp-id Number(4)

Dept-id Number(2)

Emp-name Varchar(10)

Emp-salary Number(5)

Create another table department with the following structure

Field name Data type

Dept-id Number(2)

Dept-name Varchar(10)

supervisor Varchar(10)

Assume the dept-name and dept- id as

Dept-name Dept-id

Purchase 1

Accounts 2

Sales 3

Apprentice 4

1. Enter 10 rows of data for table employee and 4 rows of data for department table
2. Find the names of all employees who work for the accounts department
3. How many employees work for accounts department
4. What is the minimum, maximum and average salary of employees working for accounts department
5. List the employees working for a particular supervisor
6. Retrieve the department names for each departments where only 1 employee works

1. create table emp(Id int(4),did int (2), name varchar(10) ,sal int(5));

2. create table dep (did int (2),dname varchar(10), supervisor varchar(10));


3. insert into emp values(100,1,’shilpa’,20000);
insert into emp values(101,2,’Anu’,15000);
insert into emp values(102,3,’Anil’,10000);
insert into emp values(103,4,’sunil’,25000);
insert into emp values(104,1,’sowmya’,20000);
insert into emp values(105,2,’swapna’,15000);
insert into emp values(106,3,’suma’,10000);
insert into emp values(107,1,’sunil’,25000);
insert into emp values(108,2,’Uma’,20000);
insert into emp values(109,3,’Devi’,15000);

4. insert into dep values(1,’purchase’,’mary’);


insert into dep values(2,’Accounts’,’suman’);
insert into dep values(3,’sales’,’Anurag’);
insert into dep values(4,’Apprentice’,’Koushik’);

5. select * from Emp;

6. select * from dep;

7. select * from emp where did =(select did from dep where dname =’accounts’);

8. select count (*) from emp where did =(select did from dep where dname=’Accounts’);

9. select min(sal),max(sal),avg(sal) from emp where did =(select did from dep where
dname=’Accounts’);

10. select * from emp where did =(select did from dep where supervisor=’suman’);

11. select dname from dep where did in (select did from emp groupby did having count(*)=1);

12. update emp set sal=sal+sal*0.15 where did=(select did from dep where dname =’sales’);

13. alter table emp add (bonus int(5));

14. update emp set bonus=sal*0.05;

15. delete from emp where did = (select did from dep where name=’Apprentice’);
SQL problem no.4
Create the following table BANK DATABASE for the ABC bank with the following structure:

FIELD NAME DATA TYPE DESCRIPTION

ACC_NUMBER NUMBER(12) Customer Account Number

CUST_NAME VARCHAR2(25) Customer Name

ACC_TYPE CHAR(2) Nature of account

BALANCE NUMBER(12) Balance amount in the account

DOT DATE Date of transaction

T_AMOUNT NUMBER(12) Transaction amount

T_TYPE CHAR(1) D for deposit W for


withdrawal

Write SQL statements for the following:

1. Find the names of all customer whose balance amount is more than Rs.30,000/-.
2. How many customer whose balance amount is less than the minimum in the account (assume that
minimum balance is Rs.1000/-).
3. Perform the transaction on T_TYPE (Deposit or withdrawal).
4. Display transaction amount on a particular day.
5. Display all the records of CA account.

1. create table cust (cno int(4) primary key, name char(20), cadd varchar(20), mob char(8));

2. create table bank (accno int(4) not NULL, tamt int(8) check (tamt>0), tdate date, ttype char,
cno int(4));

3. insert into cust values(100,’anu’,’mysore’,’93451987’);


insert into cust values(101,’balu’,’bangalore’,’83456345’);
insert into cust values(102,’anusha’,’chennai’,’94351356’);
insert into cust values(103,’sunil’,’kerala’,’93561891’);
insert into cust values(104,’sanu’,’delhi’,’NULL’);
4. insert into bank values(1, 25000,’2022/11/21’,’D’, 100);
insert into bank values(2, 35000,’2022/11/10’,’C’, 102)
insert into bank values(3, 45000,’2022/12/5’,’D’, 100);
insert into bank values(4, 30000,’2022/12/6’,’C’, 103);
insert into bank values(5, 15000,’2022/12/8’,’D’, 104);
insert into bank values(6, 75000,’2022/12/1’,’D’, 101);

5. select * from cust;

6. select * from bank;

7. select * from bank where tdate>=’2022/12/6’;

8. select accno, cust.cno, name from cust, bank where cust.cno=bank.cno;

9. select ttype, count(*) from bank group by ttype;

10. select * from cust order by name desc;

11. update bank set tamt=50000 where accno=2;

12. alter table cust modify cadd char(50);

13. delete from bank where accno=1;

14. create table tcust as (select *from cust where cno between 100 and 102);

15. select * from cust where name like ’s%’;

16. select now( );

17. select sum (tamt) from bank;

18. create view vcust as select cno, mob from cust;

19. select distinct (cno) from bank;

20. select accno, count(*) from bank group by accno having count(*)>1;

21. select * from cust where mob=’NULL’;

22. delete from cust;

23. drop table bank;

24. drop table cust;

You might also like