Struggling with custom SQL query

旧城冷巷雨未停 提交于 2019-12-13 09:54:56

问题


I have to make a query to:

show a view which shows the results of counting all the employee dedications per employee area, listed by the area names in alphabetical order.

$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)');

However, doesn't seem to be working on my website?

here is my relationships:

enter image description here


回答1:


I would recommend writing the query like this:

create temporary table temp as
    select c.industry, count(*) AS TotalFrequency
    from interest i JOIN
         customers c
         on i.staff_staffID = c.interestID
    group by c.industry;

This is just a guess. You haven't provided table layouts. The join conditions are quite strange (but wouldn't result in an error, just non-matches).



来源:https://stackoverflow.com/questions/55125970/struggling-with-custom-sql-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!