3 most profitable companies
Find the 3 most profitable companies in the entire world. Output the result along with the corresponding company name. Sort the result based on profits in descending order. Soucrs
Dataframe: forbes_global_2010_2014

#SQL Query
select company, profits as profit from forbes_global_2010_2014
order by profit desc
limit 3#Python Query
import pandas as pd
Top_3_companies= forbes_global_2010_2014.nlargest(3,'profits')
print(Top_3_companies[['company','profits']])Case# 2
Finding Doctors
Find doctors with the last name of ‘Johnson’ in the employee list. The output should contain both their first and last names.
DataFrame: employee_list


Solution
Python Code
import pandas as pd
doc_Johnson = employee_list[(employee_list['profession'] == 'Doctor') & (employee_list['last_name']== 'Johnson')]
table = doc_johnson[['first_name','last_name']]
print(table)SQL Code
SELECT first_name, last_name
FROM employee_list
WHERE profession = 'Doctor' AND last_name = 'Johnson'
Leave a Reply to Hiến bmt Cancel reply