我想弄清楚如何从多列中提取多个最大值.以下是一些示例数据:
I am trying to figure out how to pull multiple max values from multiple columns. Here is some sample data:
DATE | A | B | C
4/4/2011 | 64.4 | 62.1 | 33.3
4/5/2011 | 34.6 | 33.5 | 32.3
4/6/2011 | 33.1 | 49.4 | 32.1
4/7/2011 | 55.2 | 32.8 | 33.5
4/8/2011 | 31.2 | 50.1 | 30.4
4/9/2011 | 31.7 | 31.1 | 30.4
我想要前 5 名:
4/4/2011 | 64.4
4/4/2011 | 62.1
4/7/2011 | 55.2
4/8/2011 | 50.1
4/6/2011 | 49.4
谢谢
怎么样:
SELECT TOP 5 Date, Val
FROM (SELECT Date, A as Val FROM T
UNION ALL
SELECT Date, B FROM T
UNION ALL
SELECT DATE, C FROM T
) AS x
ORDER BY x.Val DESC
这篇关于SQL查询从多列中获取多个最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!