您可以尝试使用 JOIN
SELECT
t1.supplier_id,
t1.total_revenue,
t2.max_total_revenue,
t2.min_total_revenue
FROM (
SELECT
supplier_id,
SUM(revenue) as total_revenue
FROM orders
GROUP BY supplier_id
) t1
LEFT JOIN (
SELECT
MAX(total_revenue) max_total_revenue,
MIN(total_revenue) min_total_revenue
FROM (
SELECT
supplier_id,
SUM(revenue) as total_revenue
FROM orders
GROUP BY supplier_id
)
) t2 ON 1 = 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句