我有一个关于几家公司的数据库,包括他们的名字,份额价格,年龄变化百分比:
NAME PRICE % CHANGE
-------------------------------------------------
a 67 11
b 23 6
c 456 5.89
d 112 23.98
e 31 17
f 78 3.09
g 2678 12.56
h 357 4.6
我想选择前5行年龄%明智,意味着哪个最大%年龄显示在顶部... n先于jst 4更多值在desc中。为了...
输出应该
NAME PRICE % CHANGE
-------------------------------------------------
d 112 23.98
e 31 17
g 2678 12.56
a 67 11
b 23 6
答案 0 :(得分:8)
SELECT t.name,
t.price,
t.change
FROM TABLE t
ORDER BY t.change DESC
LIMIT 5
LIMIT
条款:
SELECT TOP 5
t.name,
t.price,
t.change
FROM TABLE t
ORDER BY t.change DESC
TOP
是supported on SQL Server 2000+ at least
SELECT x.*
FROM (SELECT t.name,
t.price,
t.change
FROM TABLE t
ORDER BY t.change DESC) x
WHERE ROWNUM <= 5
Oracle的ROWNUM
答案 1 :(得分:1)
除非我误解了某些内容......这是基本的SQL:
SELECT * FROM table ORDER BY change DESC LIMIT 5;
答案 2 :(得分:0)
这个怎么样?
SELECT * FROM table ORDER BY change DESC LIMIT 5
编辑:请注意,change
应该是您列为% CHANGE
的列的名称...
答案 3 :(得分:0)
排序和限制
SELECT * FROM company ORDER BY更改DESC LIMIT 5;
答案 4 :(得分:0)
select top 5 * from tblname order by change desc