例如:如果我有一个包含以下内容的表:
PRICES
1
5
3
8
2
8
如果我想要第二个元素,我怎么能得到它?只有那个号码..有可能吗?
答案 0 :(得分:1)
试试这个:
declare @x int
set @x = 3
select top 1
from (select top @x from table order by 1 desc) xx
答案 1 :(得分:0)
$third_element = mysql_result(mysql_query("SELECT prices FROM the_table WHERE prices = '3'"), 0);
选择元素,但我不知道为什么你会这样做,除非你有另一行从中选择它,例如WHERE other_row ='something',那么你会得到3。
答案 2 :(得分:0)
create table prices
(
price int
)
insert into prices values (1)
insert into prices values (5)
insert into prices values (3)
insert into prices values (8)
insert into prices values (2)
insert into prices values (8)
select x.* from
(
select ROW_NUMBER()over(order by price) as RowNumber,price
from prices
)x
where x.RowNumber=3