Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

employee ( employee_name , street , city ) works ( employee_name , company name

ID: 3794047 • Letter: E

Question

employee (employee_name, street, city)

works (employee_name, company name, salary)

company (company_name, city)

manages (employee_name, manager_name)

Consider the employee database of Figure 3.20, where the primary keys are underlined. Give an expression in SQL for each of the following queries.

Find the number of employees of each company. Rename the second attribute in the output as number_employees. Assume that each company has at least one employee.

##An example would be like this

Find the names of all employees who work for “First Bank Corporation”.

answer:

select employee_name

from works

where company_name = ‘First Bank Corporation’

Explanation / Answer

Hi,

Please provide the figure. I have assumed the database tables and according to that the answer is given below:

Please feel free to come up with questions.

Employee:                                                                                                         

Employee_Name

Street

City

Works:

Employee_name

Company Name

Salary


Company

Company_name

City

Manages

Employee_name

Manager_name

SELECT count(employee_name) as ‘number_employees’ FROM works

WHERE company_name IN

(

   SELECT company_name

    FROM company

   GROUP BY company_name

   HAVING COUNT(*)>0

)

group by company_name

Employee_Name

Street

City