SQL
SQL
CODE:
f=open("test.txt",'r')
read=f.readlines()
f.close()
id=[]
for ln in read:
if ln.startswith("T"):
id.append(ln)
print(id)
OUTPUT:
[Test program\n]
SQL
TABLES USED:
Customers
customer_id first_name last_name age country
1 John Doe 31 USA
2 Robert Luna 22 USA
3 David Robinson 22 UK
4 John Reinhardt 25 UK
5 Betty Doe 28 UAE
EMP
Orders
order_id item amount customer_id
1 Keyboard 400 4
2 Mouse 300 4
3 Monitor 12000 3
4 Keyboard 400 1
5 Mousepad 250 2
SQL COMMANDS.
OUTPUT:
OUTPUT:
OUTPUT:
Customers
customer_id first_name last_name age country
1 John Doe 31 USA
2 Robert Luna 22 USA
3 David Robinson 22 UK
4 John Reinhardt 25 UK
5 Betty Doe 28 UAE
OUTPUT:
country
USA
UK
UAE
count(*)
4
COMMAND 7: To display the information of customers whose age is between 20 to 25.
OUTPUT:
MIN(age)
22
AVG(age)
25.6
COMMAND 11: select first_name from customers group by age;
first_name
Robert
John
Betty
John
COMMAND 12:
select item from orders group by amount;
item
Mousepad
Mouse
Keyboard
Monitor
COMMAND 13:
select first_name from customers where first_name is NOT NULL;
first_name
John
Robert
David
John
Betty
COMMAND 14:
delete from customers where age = 31;
COMMAND 15:
select first_name , last_name from customers where age like _5;
4 John Reinhardt 25 UK
COMMAND 16:
select customer_id from customers group by age having age>22;
customer_id
4
5
COMMAND 17:
select * from customers where first_name like "%t%";
COMMAND 18:
select customer_id* age from customers;
customer_id* age
44
66
100
140
COMMAND 19:
select 15*2;
15*2
30
COMMAND :20
select first_name , age , item, amount from customers,orders;