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

CS Programme

The document contains 17 Python programs covering topics like calculating seconds in a year, date conversion, time difference, Fibonacci series, dictionary operations, sorting, currency conversion, functions, and MySQL queries; each program is accompanied by its index number, topic, page number and a signature field.

Uploaded by

RUDRA DAVE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

CS Programme

The document contains 17 Python programs covering topics like calculating seconds in a year, date conversion, time difference, Fibonacci series, dictionary operations, sorting, currency conversion, functions, and MySQL queries; each program is accompanied by its index number, topic, page number and a signature field.

Uploaded by

RUDRA DAVE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

Name: Rudra Dave

Board roll no.:


11633201
th
Class: 12 science B

INDEX
SN TOPIC PAGE SIGNATUR
O. NO. E
PYTHON PROGRAMS
1 W.A.P that calculates and prints the
number of seconds in a year.
2 W.A.P that reads a date as an integer
in the format MMDDYYYY. The
program will call a function that
prints print out the date in the format
<Monthname> <day> < year>.
3 W.A.P that reads two times in
military format (0900,1730) and
prints the number of hours and
minutes between the two times.
4 W.A.P that creates a tuple storing
first 9 terms of Fibonacci Series.
5 Create a dictionary whose keys are
months names and whose values are
the number of days in the
corresponding months.

a. Ask the user to enter a month


name and use the dictionary to tell
them how many days are in the
month
b. Print out all of the keys in
alphabetical order
c. Print out all of the months with 31
days
d. Print out the pairs sorted by the
number of days in each month.
6 W.A.P to sort a dictionary's value
using Bubble sort and produce the
sorted values as a list.
7 W.A function that takes amount in
dollars and dollar to rupee
conversion price. It returns the
amount converted as per the user
selections. Create both void and non
void forms.

SN TOPIC PAGE SIGNATURE


O. NO.
8 W.A.P to have following
functions:
a. A function that takes a
number as argument and
calculates cube for it. The
function does not return a value.
if there is no value passed to the
function call, the function should
calculate cube of 2.
b. A function that takes two
char arguments and returns True
if both the arguments are equal
otherwise false.

9 W.A. function that receives two


numbers and generates a random
number from that range. Using
this function the main program
should be able to print three
numbers randomly.
10 W.A.P a function namely nth
Root() that receives two
parameters x and n and returns
nth root of x i.e. 1/x to power n.
Default value of x is 2.

11 Write a function that takes a


number n and then returns a
randomly generated number
having exactly n digits (not
starting with zero). Example: if
n=2 then function can randomly
return a number between 10-99
then it should return numbers
from 10 till 00 below 10 are
invalid numbers.

SN TOPIC PAGE SIGNATURE


O. NO.
12 W.A.P that has a function that
takes two numbers and returns
the number that has minimum
one's value i.e. Place value of a
number.
So, 456 and 781 then it will
return 781 as place value of one's
i.e. in 781 is less then 6 of 456
number

13 W.A.P that generates a series


using a function which takes first
and last values of the series and
then generates four terms that are
equidistant e.g. if two numbers
passed are 1 and 7 then function
returns 1 3 5 7

14 Write a function with following


signature:
remove_letter(sentence, letter)
Above function takes a string and
letter as a parameter given by the
user and returns the string with
the eliminated character.
15 W.A.P to read a complete file
line by line
16 W.A.P to display the size of a
file in bytes and display the
number of lines in the file
17 W.A.P to display the content of
the Emp table and then create a
binary file having Emp table
records.
18 W.A.P that accepts student name,
student no, class and div and
store the new entry in the
tbl_Student table created in
Mysql
SN TOPIC PAGE SIGNATURE
O. NO.
19 W.A.P that displays a menu to
the user as shown below:
a. Add New Record
b. Edit Existing Record.
If the user selects (a) User enters
the data like Item name, price per
unit, and qty and inserts into the
tbl_Item_Mst having columns
like ItemNo (P.K), ItemName
varchar(80), Price float(6), Qty
int(3)
If user selects (b) Edit the
existing record and maintain the
changed record details in binary
file along with the current date.
20 W.A.P that accepts city name
from the user and then creates a
CSV file for the data that is
stored in the tbl_City_Mst having
column (CityId, CityName). If
the city is getting repeated
display the message 'City already
exist' and terminate the program
else, add it to the table also
update the CSV file with latest
data from the table.
MYSQL QUERIES BASED ON
FOLLOWING TABLES
1 tbl_product
2 tbl_customers
3 tbl_employees
4 tbl_Orders

Program1. W.A.P that calculates and prints the number of


seconds in a year.
#Program to calculate number of seconds in a year
d=365
h=24
m=60
s=60
print("Number of seconds in a year:",days*hours*minutes*seconds)
Program2. W.A.P that reads a date as an integer in the format
MMDDYYYY. The program will call a function that prints print
out the date in the format <Monthname> <day> < year>.
MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
def date_convert(s):
y = s[:4]
m = int(s[5:-3])
d = s[8:]
month_name = MONTHS[m-1]
result= month_name + ' ' + d + ' ' + y
return result
s = input("Enter the date in the format YYYY/MM/DD")
r = date_convert(s)
print(r)
OUTPUT

Program3. W.A.P that reads two times in military format


(0900,1730) and prints the number of hours and minutes between
the two times.
def time_hiest(t1, t2):
h1 = t1//100
h2 = t2//100
m1 = t1 - (h1*100)
m2 = t2 - (h2*100)
hDiff = h2 - h1
mDiff = m2 - m1
if mDiff >= 0:
print(hDiff,"hours"," ", mDiff, "mins")
else:
print(hDiff-1,"hours"," ", 60 - abs(mDiff), "mins")
t1 = int(input("Enter time1\t"))
t2 = int(input("Enter time2\t"))
time_hiest(t1, t2)
OUTPUT

Program4. .W.A.P that creates a tuple storing first 9 terms of


Fibonacci Series.
def fibonacci(n):
if n == 0:
return 0
elif n ==1 :
return 1
else:
return fibonacci(n-1)+fibonacci(n-2)
fib = ()
for i in range(9):
fib += (fibonacci(i),)
print(fib)
OUTPUT

Program5. Create a dictionary whose keys are months names and


whose values are the number of days in the corresponding
months.
a.Ask the user to enter a month name and use the dictionary to
tell them how many days are in the month
b. Print out all of the keys in alphabetical order
c. Print out all of the months with 31 days
d. Print out the pairs sorted by the number of days in each month
(A) m = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" :
31 , "june" : 30 , "july" : 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 ,
"nov" : 30 , "dec" : 31}
mon = input("enter the mounth name in short form = ")
print("number of days in ",mon,"=",m [ mon ])
output:

(B) m = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" :


31 , "june" : 30 , "july" : 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 ,
"nov" : 30 , "dec" : 31}
lst = list ( m . keys() )
lst.sort()
print( lst )
print( "month which have 31 days --- ")
Output:
(C) m = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" :
31 , "june" : 30 , "july" : 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 ,
"nov" : 30 , "dec" : 31}
for i in m :
if m [ i ] == 31 :
print( i )
print("month according to number of days ---")
Output:
(D) m = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" :
31 , "june" : 30 , "july" : 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 ,
"nov" : 30 , "dec" : 31}
for i in m :
if m [ i ] == 30 :
print(i)
for i in m :
if m [ i ] == 31 :
print( i )
OUTPUT:

Program6. W.A.P to sort a dictionary's value using Bubble sort


and produce the sorted values as a list
def b_sort(list) :
for i in range(1,len(k)):
for j in range (len(k)-i):
if k[j]>k[j+1]:
k[j],k[j+1]=k[j+1],k[j]
return k
d = {'c':1,'f':22,'a':13,'d':4 ,'e':5,'h':8}
k=list (d.keys())
print(b_sort(k))
OUTPUT
7. W.A function that takes amount in dollars and dollar to rupee
conversion price. It return the amount converted as per the user
selections. Create both void and non void forms.
def dTor_Void(dollar):
print(dollar*75)
def dTor_nonVoid(dollar):
return dollar*75
amt = float(input("Enters dollars\t"))
funcType = input("Enter Function type (V / NV)\t")
if funcType == "V":
dTor_Void(amt)
elif funcType == "NV":
print(dTor_nonVoid(amt))
else:
print("invalid input")
OUTPUT
Program8. W.A.P to have following functions:
a. A function that takes a number as argument and calculates
cube for it. The function does not return a value. if there is no
value passed to the function call, the function should calculate
cube of 2.
b. A function that takes two char arguments and returns True if
both the arguments are equal otherwise false.
def cube(num=2):
c = num**3
print(c)
def same_or_not(char1, char2):
if char1 == char2:
print("True")
else:
print("False")
choice=int(input("Enter your choice 1 or 2"))
if choice==1:
a=input("Enter a no.")
if a=='':
i=2
cube(i)
else:
b=int(a)
cube(b)
else:
char1=input("Enter a char1")
char2=input("Enter a char2")
same_or_not(char1,char2)
Program9. W.A. function that receives two numbers and
generates a random number from that range. Using this funciton
the main program should be able to print three numbers
randomly.
import random
import random as rd
def generateRandom(l, u):
return rd.randrange(l,u), rd.randrange(l,u), rd.randrange(l,u)
lower = int(input("enter lower limit\t"))
upper = int(input("enter upper limit\t"))
a, b, c = generateRandom(lower, upper)
print(a, b, c)
OUTPUT
Program10. Write a function namely nthRoot() that receives two
parameters x and n and returns nth root of x i.e. 1/x to power n.
Default value of x is 2.
def nR(n, x=2):
return x**(1/n)
n = int(input("Enter value of n\t"))
x = input("Enter num\t")
if not(x):
print(nR(n))
else:
print(nR(n,int(x)))
OUTPUT
Program11. Write a function that takes a number n and then
returns a randomly generated number having exactly n digits (not
starting with zero). Example: if n=2 then function can randomly
return a number between 10-99 then it should return numbers
from 10 till 00 below 10 are invalid numbers.
import random as rd
def gR(n):
l = 10 ** (n-1)
u = 10 ** (n)
print(l,u)
return rd.randrange(l,u)
n = int(input("Enter value of n\t"))
print(gR(n))
OUTPUT
Program12. Write a function that takes two numbers and returns
the number that has minimum one's value i.e. Place value of a
number .So 456 and 781 then it will return 781 as place value of
one's i.e in 781 is less then 6 of 456 number
def x(n1, n2):
n = n1 - ((n1//10)*10)
s = n2 - ((n2//10)*10)
print(n, s)
if n > s:
return n2
elif n < s:
return n1
else:
return
print(x(16843, 5682))
OUTPUT

Program13. W.A.P that generates a series using a function which


takes first and last values of the series and then generates four
terms that are equidistant e.g. if two numbers passed are 1 and 7
then function returns 1 3 5 7
def equi4Series(l, u):
d = (u-l)/3
return l, l+d, l+2*d, u
lower = int(input("enter lower limit\t"))
upper = int(input("enter upper limit\t"))
a, b, c, d = equi4Series(lower, upper)
print(a, b, c, d)
OUTPUT
Program14. Write a funciton with following signature:
remove_letter(sentence, letter)
Above function takes a string and letter as a parameter given by
the user and returns the string with the eliminated character.
def remove_letter(sentence, letter):
resultStr = ""
for i in sentence:
if not(i == letter):
resultStr += i
return resultStr
sentence = input("Enter sentence\t")
letter = input("Enter letter\t")

print(remove_letter(sentence, letter))
OUTPUT

Program15. W.A.P to read a complete file line by line


file_path = r"D:\Poem.txt"
file_obj = open(file_path)
print(file_obj.read())
OUTPUT
16. W.A.P to display the size of a file in bytes and display the
number of lines in the file
file_path = r"D:\poem.txt"
file_obj = open(file_path)
print(file_obj.read())

file = open("D:\Poem.txt","r")
Counter = 0

Content = file.read()
CoList = Content.split("\n")

for i in CoList:
if i:
Counter += 1

print("This is the number of lines in the file")


print(Counter)

import os

file_size = os.stat('D:/Poem.txt')
print("Size of file :", file_size.st_size, "bytes")
OUTPUT

Program17. W.A.P to display the content of the Emp table and


then create a binary file having Emp table records.
import pickle
emp={'Namita':25000,'Manya':30000,'Tanu':20000}
f1=open('emp.dat','wb')
pickle.dump(emp,f1)
f1.close()
f1=open('emp.dat','rb')
e=pickle.load(f1)
for x in e:
print(x)
f1.close()  
OUTPUT

Program18. W.A.P that accepts student name, student no, class


and div and store the new entry in the tbl_Student table created
in Mysql
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="mydatabase"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE Student (name


VARCHAR(255), student_no int,Class VARCHAR(2),Div
VARCHAR(2))")
mycursor.execute("INSERT INTO Student VALUES
(“ADITYA”,2 ,’XII’,”SCI” ))

19. W.A.P that displays a menu to the user as shown below:


a. Add New Record
b. Edit Existing Record.
If the user selects (a) User enters the data like Item name, price
per unit, and qty and inserts into the tbl_Item_Mst having
columns like ItemNo (P.K), ItemName varchar(80), Price float(6),
Qty int(3).If user selects (b) Edit the existing record and maintain
the changed record details in binary file along with the current
date.
import mysql.connector
myconn=mysql.connector.connect(host="localhost",user="root",pass
wd="aditya",database="project")
cur=myconn.cursor()
a="create table tbl_Item_Mst(ItemNo int(10) primary key, ItemName
varchar(80), Price float(6), Qty int(3))"
cur.execute(a)
myconn.commit()
print("""What do you want to do:
1)Add new record
2)Edit existing record""")
ans=int(input("Enter your choice:"))
if ans==1:
INo=int(input("Enter item number:"))
IN=input("Enter item name:")
PPU=float(input("Enter price per unit:"))
Q=int(input("Enter item quantity:"))
b="insert into tbl_Item_Mst values({},'{}',{},
{})".format(INo,IN,PPU,Q)
cur.execute(b)
myconn.commit()
else:
myfile=open("stalk.txt","w")
INo1=int(input("Enter item number:"))
IN1=input("Enter item name:")
PPU1=float(input("Enter price per unit:"))
Q1=int(input("Enter item quantity:"))
c="update tbl_Item_Mst set
ItemNo={},ItemName='{}',Price={},Qty={}".format(INo1,IN1,PPU1
,Q1)
myfile.close()
20. W.A.P that accepts city name from the user and then creates a
CSV file for the data that is stored in the tbl_City_Mst having
column (CityId, CityName). If the city is getting repeated display
the message 'City already exist' and terminate the program else,
add it to the table also update the CSV file with latest data from
the table.
import pickle
c={}
found=False
#SELECT * FROM myTable INTO OUTFILE
'C:\Users\DELL\Desktop\Data.csv' FIELDS ENCLOSED BY '"'
TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY
'\r\n';
CN=input("Enter the city name")
myfile=open("Data.txt","rb+")
try:
while True:
rpos=myfile.tell()
c=pickle.load(myfile)
if c['City name']==CN:
print("City already exist!!Can't enter")
found=True
else:
c['City name']=CN
myfile.seek(rpos)
pickle.dump(c,myfile)
except:
pass

Q-1 Create the command for the following:


1. To create database by name ‘db_Logistics’.
Create database db_Logistics;
2. Open the database to create the table.
Use db_Logistics;
3. Create the following table with following structure:
Create table tbl_product(ProductId int(11),ProductName
varchar(40),SupplierId int(11),CategoryId
int(11),QuantityPerUnit varchar(20), UnitPrice decimal(10,4),
UnitsInStock smallint(2), UnitsOnOrder smallint(2),
ReorderLevel smallint(2));
Table Name: tbl_Products.
Column D Siz
Name a e
t
a
T
y
p
e
ProductId I 11
n
t
ProductN V 40
ame a
r
c
h
a
r
SupplierI I 11
d n
t
CategoryI I 11
d n
t
QuantityP V 20
erUnit a
r
c
h
a
r
UnitPrice D (10
e ,4)
c
i
m
a
l
UnitsInSt S 2
ock M
A
L
L

I
N
T
UnitsOnO S 2
rder M
A
L
L

I
N
T
ReorderL S 2
evel M
A
L
L

I
N
T

ProductI P Su Categ QuantityPer Uni Units UnitsO Reor


r
o
d
u
c
t
N
a ppl
m ierI tPri InSto derLe
D e D oryID Unit ce ck nOrder vel
C
h
a 10 boxes x
1 i 1 1 20 bags 18 39 0 10
C
h
a
n 24 - 12 oz
2 g 1 1 bottles 19 17 40 25
A
n
i
s
e
e
d
S
y
r
u 12 - 550 ml
3 p 1 2 bottles 10 13 70 25
4 C2 2 48 - 6 oz 22 53 0 0
h jars
e
f
A
n
t
o
n
'
s
C
a
j
u
n
S
e
a
s
o
n
i
n
g
5 C2 2 36 boxes 21. 0 0 0
h 35
e
f
A
n
t
o
n
'
s
G
u
m
b
o
M
i
x
G
r
a
n
d
m
a
'
s
B
o
y
s
e
n
b
e
r
r
y
S
p
r
e
a 12 - 8 oz
6 d 3 2 jars 25 120 0 25
7 U3 7 12 - 1 lb 30 15 0 10
n pkgs.
c
l
e
B
o
b
'
s
O
r
g
a
n
i
c
D
r
i
e
d
P
e
a
r
s
8 N3 2 12 - 12 oz 40 6 0 0
o jars
r
t
h
w
o
o
d
s
C
r
a
n
b
e
r
r
y
S
a
u
c
e
M
i
s
h
i
K
o
b
e
N
i
k 18 - 500 g
9 u 4 6 pkgs. 97 29 0 0
I
k
u
r 12 - 200 ml
10 a 4 8 jars 31 31 0 0
11 Q5 4 1 kg pkg. 21 22 30 30
u
e
s
o
C
a
b
r
a
l
e
s
Q
u
e
s
o
M
a
n
c
h
e
g
o
L
a
P
a
s
t
o
r 10 - 500 g
12 a 5 4 pkgs. 38 86 0 0
13 K6 8 2 kg box 6 24 0 5
o
n
b
u
T
o
f 40 - 100 g 23.
14 u 6 7 pkgs. 25 35 0 0
G
e
n
e
n
S
h
o
u
y 24 - 250 ml 15.
15 u 6 2 bottles 5 39 0 5
Q-2 Insert following data into the above mentioned table: (NOTE:
in file write 5 insert statements):
insert into tbl_products values
(1,'Chai',1,1,'10boxesx20bags',18,39,0,10),
(2,'Chang',1,1,'24-12ozbottles',19,17,40,25),
(3,'Anissed syrup',1,1,'12-550mlbottles',10,13,70,25),
(4,'Chef antons cajun seasoning',1,2,'48-6ozjars',22,53,0,0),
(5,'Chef antons gumbo mix',2,2,'36boxes',21.35,0,0,0),
(6,'Grandma boysenberry',3,2,'12-8ozjars',25,120,0,25),
(7,'Bob organic Dried Pears',3,7,'12-1lbpkgs',30,15,0,25),
(8,'Northwoods Cranberry',3,2,'12-12ozjars',40,6,0,0),
(9,'Mishi Kobe',4,6,'18-500gpkgs',97,29,0,0),
(10,'Ikura',4,8,'12-200mljars',31,31,0,0),
(11,'Queso cabrales',5,4,'1kgpkg',21,22,30,30),
(12,'Queso Manchego',5,4,'10-500gpkgs',38,86,0,0),
(13,'Konbu',6,8,'2KgBox',6,24,0,5),
(14,'Tofu',6,7,'40-100gpkgs',23.25,35,0,0),
(15,'Genen',6,2,'24-250mlbottles',15.5,39,0,5);
OUTPUT
Q-3 Write SELECT statement write queries for the following
questions:
1. Write a query to get Product name and quantity/unit.
select ProductName,QuantityPerUnit from tbl_products;

2. Write a query to get current Product list (Product ID and


name).
select concat(ProductName,'-',ProductId) as 'Current Product
list' from tbl_products;
3. Write a query to get most expense and least expensive
Product list (name and unit price). 
select * from tbl_products where UnitPrice in ((select
min(UnitPrice) from tbl_products),(select max(UnitPrice) from
tbl_products));

4. Write a query to get Product list (id, name, unit price) where


current products cost less than $20.
select ProductId,ProductName,UnitPrice from tbl_products
where UnitPrice<=20;
5. Write a query to get Product list (id, name, unit price) where
products cost between $15 and $25.
select ProductId,ProductName,UnitPrice from tbl_products
where UnitPrice<=25 and UnitPrice>=15;

6. Write a query to get Product list (name, units on order ,


units in stock) of stock is less than the quantity on order.
select ProductName,UnitsInStock,UnitsOnOrder from
tbl_products where UnitsInStock < UnitsOnOrder;

Q-4 Add Primary key constraint to the column ProductID in


table
tbl_Products.
alter table tbl_products modify ProductId int PRIMARY KEY;
Q-5 change the size of the SupplierId and CategoryID column
to 5
alter table tbl_products modify SupplierId int(5);
alter table tbl_products modify CategoryId int(5);

Q-6 Change the column name SupplierId to Supp_ID


alter table tbl_products change column SupplierId Supp_ID int(5);

Q-7 Add a new column OrderDate date


alter table tbl_products add OrderDate date;

Q-8 Drop the column OrderDate


alter table tbl_products drop OrderDate;
Q-9 Create the table tbl_Customers with following columns
and
data:
customer_id last_name first_name favorite_website
4000 Jackson Joe techonthenet.com
5000 Smith Jane digminecraft.com
6000 Ferguson Samantha bigactivities.com
7000 Reynolds Allen
checkyourmath.com
8000 Anderson Paige NULL
9000 Johnson Derek techonthenet.com
Create table tbl_Customers(
Customer_id varchar(8),
last_name varchar(20),
first_name varchar(20),
favorite_website varchar(50));
desc tbl_customers;

insert into tbl_customers values


('4000','Jackson','Joe','techonthenet.com'),
('5000','Smith','Jane','digminecraft.com'),
('6000','Ferguson','Samantha','bigactivities.com'),
('7000','Reynolds','Allen','checkyourmath.com'),
('8000','Anderson','Paige',NULL),
('9000','Johnson','Derek','techonthenet.com');
To display the names of the customers having last_name
starting
with ‘J’ and order the result by Customer_ID in descending
order.
select * from tbl_customers where last_name like 'j%' order by
customer_id desc;

Q-10 Create the following table tbl_employees with following


data
and write SQL query for the following questions:
empnumber last_name first_name salary dept_id
1001 Smith John 62000 500
1002 Anderson Jane 57500 500
1003 Everest Brad 71000 501
1004 Horvath Jack 42000 501
Create table tbl_employees(
empnumber varchar(5),
last_name varchar(20),
first_name varchar(20),
salary int,
dept_id varchar(5));
insert into tbl_employees values
('1001','Smith','John',62000,'500'),
('1002','Anderson','Jane',57500,'500'),
('1003','Everest','Brad',71000,'501'),
('1004','Horvath','Jack',42000,'501');
1.Using GROUP BY find sum of salary department wise.
select dept_id,sum(salary) from tbl_employees group by dept_id;

2. List the minimum salary department wise


select dept_id,min(salary) from tbl_employees group by dept_id;
3.Display the maximum salary department wise
select dept_id,max(salary) from tbl_employees group by dept_id;

4.Display the count of employees having salary greater than


50000
select count(*) from tbl_employees where salary > 50000;

Q-11 Create the following table ‘tbl_Orders’ having following


data:
order_id customer_id order_date
1 7000 2016/04/18
2 5000 2016/04/18
3 8000 2016/04/19
4 4000 2016/04/20
5 NULL 2016/05/01
create table tbl_orders(
order_id varchar(5),
customer_id varchar(8),
order_date date);
insert into tbl_orders values
('1','7000','2016/04/18'),
('2','5000','2016/04/18'),
('3','8000','2016/04/19'),
('4','4000','2016/04/20'),
('5',NULL,'2016/05/01');

1. List customer_id, order_id, order_date from tbl_Customer


and tbl_Orders using INNER JOIN
select * from tbl_customers;
select * from tbl_orders;

select c.*,o.order_id,o.order_date from tbl_customers c left join


tbl_orders o on c.customer_id=o.customer_id where
o.customer_id is
not null;
2. List all records of tbl_Orders having related records from
tbl_Customers
select c.*,o.order_id,o.order_date from tbl_orders o left join
tbl_customers c on c.customer_id=o.customer_id where
o.customer_id is not null;

select * from tbl_orders o left join tbl_customers c on


c.customer_id=o.customer_id where o.customer_id is not null;

You might also like