问题
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