select max(value) from customer where value not in (select max(value) from customer)
在查询中,in 或 not in *** 作符是索引失效,速度变慢,可以用以下表连接的方法,
select max(value) from (select value from customer) as a left join (select max(value) as c from customer) as b on b.c=a.value where b.c is null
一般来说,以上两种方法的执行速度 表连接的方法好些,但也应该进行测试,我认为,采用两次查询的方法比较合适,select max(value) from customer 得到最大值,
select max(value) from customer where value <6003
得到次大值。
excel 你用下面的公式:=INDEX(A$2:A$4,MATCH(LARGE(B$2:B$4,2),B$2:B$4))
解释:
1、LARGE(B$2:B$4,2): 求出B列第二大的值
如果有重复的值,用:
LARGE(B$2:B$4,COUNTIF(B$2:B$4,MAX(B$2:B$4))+1)
2、MATCH(LARGE(B$2:B$4,2),B$2:B$4) 找出第二大的值在数组中的位置
3、INDEX(A$2:A$4,MATCH(LARGE(B$2:B$4,2),B$2:B$4))
找出A列数组中,与B列相同行所对应的值
select top 1 A,B from (
select top 2 A,B from 表 order by B desc
)
order by B
SELECT *FROM (SELECT b.*
FROM (SELECT *
FROM (SELECT *
FROM book
ORDER BY date1 DESC)
WHERE ROWNUM = 1) a,
book b
WHERE a.bookname <>b.bookname
ORDER BY b.date1 DESC)
WHERE ROWNUM = 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)