我试图弄清楚如何从多个列中提取多个最大值。以下是一些示例数据:
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