56,679
社区成员
发帖
与我相关
我的任务
分享
select const(*),type from first group by type;
能得到每类的记录数,通过表达式也能定位到第二大的记录应该是哪行。
# 查找每一条记录中有相同type的所有记录,统计code大于本条记录的数量,如果只有一条记录的code大于本条记录,则本条记录的code
# 就是第二大的,并用 exists 将本条记录筛选出来。
select *
from first as a
where exists(select count(*) as num
from first
where a.type = type and a.code < code
having num = 1);