sqlite 使用SQL查询有困难[已关闭]

t0ybt7op  于 2023-03-30  发布在  SQLite
关注(0)|答案(1)|浏览(108)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

去年关闭了。
Improve this question
我正在处理一个问题,我必须创建一个SQL查询,检索所有员工及其支持的客户的发票总额。请按发票总额的降序排列结果集。
以下是该架构:

下面是问题的输出:

下面是我的SQL查询:

select e.EmployeeId,  avg(i.Total) as total 
from employees as e, invoices as i ;
ef1yzkbh

ef1yzkbh1#

连接3个表并应用order by;我猜这没问题,因为模型没有显示整个invoices表(“4个列”,嗯?)

select e.employee_id,
       sum(i.total) as sum_total
from employees e join customers c on c.supportrepid = e.employee_id
                 join invoices i on i.customerid = c.customerid
group by e.employee_id
order by 2 desc

相关问题