挣扎与网站的自定义SQL查询

时间:2019-03-14 17:46:07

标签: mysql sql

我必须查询以下内容:

显示一个视图,该视图显示计算每个员工区域所有员工奉献的结果,并按字母顺序按区域名称列出。

$this->db->query('create temporary table temp as (select dedication.employee_employeeID, dedication ID, COUNT(area) AS TotalFrequency from dedication, employees where dedication.employee_employeeID = dedication group by dedication.employee_employeeID)');

但是,我的网站上似乎没有工作吗?

这是我的关系:

https://i.stack.imgur.com/gDdN5.png

1 个答案:

答案 0 :(得分:0)

您可能想要这样的SQL语句:

create temporary table temp as (
  select
    e.employee_ID,
    e.full_name,
    a.business_ID,
    a.business,
    count(*) as dedications
  from employee e
  join dedication d on d.employee_employeeID = e.employee_ID
  join employee_area ea on ea.employee_employeeID = e.employee_ID
  join business_area a on a.business_ID = ea.business_area_business_ID
  group by e.employee_ID, a.business_ID
  order by a.business
)