注:仅可用于简单查询中
use sql_invoicing;
select *
from (
select
client_id,name,
(select sum(invoice_total)from invoices where client_id = c.client_id) as total_sale,
-- select中使用子查询生成total_sale where是为了子查询中的client_id 和外查询的client_id连接对应
(select avg(invoice_total)from invoices) as average -- select中使用子查询生成average
from clients c
) as sale_summary
where total_sale is not null