Computer Science
Write a program to display all records in ascending order of their salary from table employee.
Python MySQL
3 Likes
Answer
Table Employee:
| EMPNO | ENAME | DEPT | SALARY |
|---|---|---|---|
| 1 | RAJESH | IT | 60000 |
| 2 | MANOJ KUMAR | HISTORY | 65000 |
| 3 | ANUSHA | MARKETING | 70000 |
| 4 | ABHAY | FASHION STUDIES | 45000 |
import mysql.connector
mydb = mysql.connector.connect(host = "localhost", user = "root", passwd = "tiger", database = "School")
mycursor = mydb.cursor()
mycursor.execute("select * FROM EMPLOYEE ORDER BY SALARY")
myrecords = mycursor.fetchall()
for row in myrecords:
print(row)
mycursor.close()
mydb.close()
Output
(4, 'ABHAY', 'FASHION STUDIES', 45000.0)
(1, 'RAJESH', 'IT', 60000.0)
(2, 'MANOJ KUMAR', 'HISTORY', 65000.0)
(3, 'ANUSHA', 'MARKETING', 70000.0)
Answered By
1 Like
Related Questions
Which function/method do you use for executing an SQL query ?
Which function is used to read one record from the database?
Write a program to increase salary of the employee, whose name is "MANOJ KUMAR", by 3000.
Write a program to delete the employee record whose name is read from keyboard at execution time.