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

Main

Mysql with python

Uploaded by

kunalffserver1
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)
11 views

Main

Mysql with python

Uploaded by

kunalffserver1
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/ 12

================================================

 PROGRAM TO CHANGE THE FIRST WORD OF EACH LINE TO


UPPERCASE AND DISPLAY ALL LINES WITH LINE NUMBER AND
TOTAL NUMBER OF LINES IN A TEXT FILE USING readlines()
FUNCTION
================================================

f=open("C://py//record.txt","r")
count=0
lno=1
lines=f.readlines()
for l in lines: #read line by line
words=l.split() #seperate words in each line
line=""
for w in words:
if w==words[0]:
line+=w.upper()+" "
else:
line+=w+" "

print ("Line number",lno,":",line)


lno+=1
count+=1
print()
print (count,"lines read in the text file.")
f.close()

================================================
OUTPUT
================================================
============================================
MYSQL COMMANDS
============================================

 TO CREATE A TABLE EMPLOYEE WITH BASIC DETAILS.

 TO INSERT RECORDS IN THE EMPLOYEE TABLE.


 TO DISPLAY ALL THE RECORDS/TUPLES STORED IN THE
TABLE.

 TO DISPLAY SELECTED COLUMNS FROM THE TABLE


STORED IN THE TABLE.

 TO ADD A NEW COLUMN ‘EMPDESIG’ WITH DATA TYPE


VARCHAR(20).
 TO UPDATE VALUES IN EMPDESIG FILED.

UPDATED TABLE:-
 TO CHANGE THE DATA TYPE OF EMPNAME FROM
VARCHAR(25) TO CHAR(20).

 TO DISPLAY THE DATA IN ASCENDING AND DESCENDING


ORDER.
 TO DELETE A RECORD FROM A TABLE.

 TO DISPLAY THE MINIMUM, MAXIMUM AND AVERAGE


SALARY.

 TO COUNT THE NUMBER OF MALES AND FEMALES IN THE


EMPLOYEE TABLE.

 TO DISPLAY DEPARTMENT WISE TOTAL SALARY.


 TO DISPLAY DEPARTMENT WISE TOTAL SALARY WHERE
TOTAL SALARY IS MORE THAN 60000.

 TO DISPLAY THE DETAIL OF THOSE EMPLOYEE WHOSE


NAME CONTAINS ‘I’ IN THE NAME.

 TO DISPLAY THE DETAIL OF THOSE EMPLOYEE WHOSE


NAME CONTAINS ONLY 5 CHARACTERS.
JOINING TABLES
Table1: empl

EMPNO ENAME JOB SAL DEPTNO


8369 SMITH CLERK 2985 10

8499 ANYA SALESMAN 9870 20


8566 AMIR SALESMAN 8760 30
8698 BINA MANAGER 5643 20

Table2: dept
DEPTNO DNAME LOC
10 ACCOUNTING NEW DELHI
20 RESEARCH CHENNAI

30 SALES KOLKATA

40 OPERATIONS MUMBAI

 TO CREATE REFERENCE BETWEEN TWO TABLES.

 TO DROP A TABLE FROM DATABASE.

 CARTESIAN PRODUCT/UNRESTRICTED JOIN/CROSS JOIN


 SELECT * FROM EMPL, DEPT;

EQUI-JOIN: The join in which columns are compared for


equality, is called equi- join. In equi-join, all the columns
from joining table appear in the output even if they are
identical.
e.g. SELECT * FROM empl, dept WHERE empl.deptno = dept.deptno ;

 WITH REFERENCE TO EMPL AND DEPT TABLE, FIND THE


LOCATION OF EMPLOYEE SMITH.

 SELECT NAME, LOC FROM EMPL, DEPT


WHERE EMPL.DEPTNO = DEPT.DEPTNO AND ENAME=’SMITH’;
 DISPLAY DETAILS LIKE DEPARTMENT NUMBER,
DEPARTMENT NAME, EMPLOYEE NUMBER, EMPLOYEE
NAME, JOB AND SALARY. AND ORDER THE ROWS BY
DEPARTMENT NUMBER.

 SELECT EMPL.deptno, dname, empno, ename, job, sal


FROM EMPL, DEPT WHERE EMPL.deptno = DEPT.deptno order by
EMPL.deptno;

 DISPLAY DETAILS LIKE DEPARTMENT NUMBER,


DEPARTMENT NAME, EMPLOYEE NUMBER,
EMPLOYEE NAME, JOB AND SALARY. AND ORDER
THE ROWS BY EMPLOYEE NUMBER WITH
DEPARTMENT NUMBER. THESE DETAILS SHOULD
BE ONLY FOR EMPLOYEES EARNING ATLEAST
RS. 6000 AND OF SALES DEPARTMENT.

 SELECT E.DEPTNO, DNAME,EMPNO, ENAME, JOB, SAL


FROM EMPL E, DEPT D WHERE E.DEPTNO = D.DEPTNO AND
DNAME=’SALES’ AND SAL>=6000 ORDER BY E.DEPTNO;
NATURAL-JOIN: By default, the results of an equijoin contain
two identical columns. One of the two identical columns can be
eliminated by restating the query. This result is called a natural
join.
e.g. SELECT empno, ename, job, sal, deptno, dname, loc
WHERE empl.deptno = dept.deptno;

LEFT-JOIN: You can use left join clause in select to produce left
join i.e. when using left join all rows from the first table will be
returned whether there are matches in the second table or not.
For unmatched rows of first table, null is shown in columns of
second table.
Consider the following two tables
S1 S2
Roll_no Name Roll_no Class
1 A 2 III
2 B 4 IX
3 C 1 IV
4 D 3 V
5 E 7 I
6 F 8 II

 SELECT S1.ROLL_NO, NAME, CLASS


FROM S1 LEFT JOIN S2 ON S1.ROLL_NO=S2.ROLL_NO;
RIGHT-JOIN: It works just like left join but with table order reversed.
All rows from the second table are going to be returned whether or
not there are matches in the first table.
You can use right join in select to produce right join i.e.
e.g SELECT S1.ROLL_NO, NAME,CLASS FROM S1 RIGHT JOIN S2 ON
S1.ROLL_NO=S2.ROLL_NO;

You might also like