我试图得到两列,frequencyfrequency - min(frequency)但是我看到的是第二列的0。可能是什么问题?

SELECT
    frequency, frequency - min(frequency)
    FROM
    words
GROUP BY id
ORDER BY frequency;

sql - SQL min函数-LMLPHP

最佳答案

您的查询按频率的唯一值分组。在每个这样的组中,最小的频率就是频率本身,所以在减去这两个值时,总是得到0。相反,您可以使用窗口版本的min

SELECT   frequency, frequency - MIN(frequency) OVER() AS diff
FROM     words
ORDER BY frequency

关于sql - SQL min函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34307922/

10-12 13:07