查找max - SQL

时间:2017-09-18 18:35:27

标签: sql

我需要打印(显示)由以下代码创建的表的最大值:

SELECT name, SUM(cost)+SUM(DISTINCT stock*cost) AS result 
FROM publishers 
   NATURAL JOIN editions 
   NATURAL JOIN shipments 
   NATURAL JOIN stock 
GROUP BY name 

我尝试过使用DESC但不允许使用它

1 个答案:

答案 0 :(得分:2)

SELECT MAX(result) from (SELECT name, SUM(cost)+SUM(DISTINCT stock*cost) AS result FROM publishers NATURAL JOIN editions NATURAL JOIN shipments NATURAL JOIN stock group by name )

如果您只需要result的最大值,则应该执行此嵌套查询。