<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 [0] Database management
Python provides a interface with the databases GadFly, mSQL, MySQL, PostgreSQL, Microsoft SQL Server 2000, Informix, Interbase, Oracle, and Sybase.
Example (MySQL)
Step1:  Exercise 1
Step2:  Exercise 2
Step3:  Exercise 3
Step4:  Exercise 4
Step5:  Exercise 5
Step6:  Exercise 6
<ASSISTANT_TASK:>
Python Code:
# Source: Manuel Torres. Universidad de Almería.
import pymysql
# Establecemos la conexion con la base de datos
bd = pymysql.connect("localhost", "root", "gebd", "RRHH")
 
# Preparamos el cursor que nos va a ayudar a realizar las operaciones con la base de datos
cursor = bd.cursor()
 
# Ejecutamos un query SQL usando el metodo execute() que nos proporciona el cursor
cursor.execute("SELECT * FROM Empleado")
 
resultado = cursor.fetchall()
 
# Extraemos una sola fila usando el metodo fetchone()
for fila in resultado:
    print("%s %s %s" % (fila[0], fila[1], fila[2]))
 
# Nos desconectamos de la base de datos
bd.close()
resultado[0][2]
Explanation: [0] Database management
Python provides a interface with the databases GadFly, mSQL, MySQL, PostgreSQL, Microsoft SQL Server 2000, Informix, Interbase, Oracle, and Sybase.
Example (MySQL):
pip install pymysql
End of explanation
all_jobs = [x[2] for x in resultado]
all_jobs = []
for i in resultado:
    all_jobs.append(i[2])
all_jobs
Explanation: Exercise 1:
Create a list with the jobs of the third column of resultado. Tip: a list comprehension can be useful!
End of explanation
diff_jobs = set(all_jobs)
diff_jobs
Explanation: Exercise 2:
Compute a set of different jobs in resultado (this set will store some may items a different jobs are found in resultado). Clue: sets cannot store dupplicate elements!
End of explanation
jobs_count = {}
for i in diff_jobs:
    jobs_count[i] = 0
jobs_count
for i in all_jobs:
    jobs_count[i] += 1
jobs_count
jobs_count = {}
for i in diff_jobs:
    jobs_count[i] = all_jobs.count(i)
jobs_count
jobs_count['Analista']
Explanation: Exercise 3:
Compute the number of occurrences of each job in resultado. This can be accomplished by generating a dictionary with a structure: {job:number_of_occurrences}. Tip: use the result of the previous exercise (a set of different jobs) to create the required dictionary.
End of explanation
count_jobs = []
for i in jobs_count:
    count_jobs.append((jobs_count[i], i))
count_jobs
Explanation: Exercise 4:
Python dictionaries cannot be sorted (by definition). For this reason, create a list of tuples with a structure (number_of_ocurrences, job), using as input the result of the previous exercise.
End of explanation
sorted_count_jobs = sorted(count_jobs, reverse=True)
sorted_count_jobs
sorted_count_jobs[1][1]
Explanation: Exercise 5:
Sort (in reverse order) the previous list. Create a sorted list (in descending order) of tuples with a structure (number_of_ocurrences, job), using as input the result of the previous exercise. Tip: visit https://docs.python.org/3/howto/sorting.html#sortinghowto and find out how you can use the reverse=True parameter.
End of explanation
i = 1
most_common_jobs = [(sorted_count_jobs[0][1], sorted_count_jobs[0][0])]
most_common_jobs
while(sorted_count_jobs[i][0] == sorted_count_jobs[0][0]):
    x = (sorted_count_jobs[i][1], sorted_count_jobs[i][0])
    most_common_jobs.append(x)
    i += 1
most_common_jobs
Explanation: Exercise 6:
Compute the most common job(s) in resultado. Create a list of tuples with a structure (job, number_of_ocurrences) with the most common job(s), using as input the result of the previous exercise.
End of explanation
<END_TASK>