求一SQL语句:怎么查询最大的前3个值

已举报 回答
求一SQL语句:怎么查询最大的前3个值
问在线客服
扫码问在线客服
  • 回答数

    5

  • 浏览数

    9,551

5个回答 默认排序
  • 默认排序
  • 按时间排序

已采纳
select top 3 查询字段 from 表 order by 查询字段 desc
取消 评论
假设你的原表叫eat,我新建一张表叫eat_pay,字段是 (用餐时段 姓名 用餐次数)
create table eat_pay as
select '06:00-10:29' as 早餐时间,t.name as 员工姓名,count(name) as 用餐次数 from eat t
where to_char(time,'HH24:MI')'06:00' and to_char(time,'HH24:MI') '10:29'
group by name

insert into eat_pay
select '10:30-14:59' as 中餐时间,t.name as 员工姓名,count(name) as 用餐次数 from eat t where to_char(time,'HH24:MI')'10:30' and to_char(time,'HH24:MI') '14:59' group by name

insert into eat_pay
select '15:00-20:59' as 晚餐时间,t.name as 员工姓名,count(name) as 用餐次数 from eat t where to_char(time,'HH24:MI')'15:00' and to_char(time,'HH24:MI') '20:59' group by name

insert into eat_pay
select '21:00-23:29' as 宵夜时间,t.name as 员工姓名,count(name) as 用餐次数 from eat t
where to_char(time,'HH24:MI')'21:00' and to_char(time,'HH24:MI') '23:29' group by name

最后select * from eat_pay 可以看到你要的结果
取消 评论
MySQL用法:SELECT `字段名` FROM `表名` order by `字段名` desc limit 3
MSSQL用法:select top 3 '字段名' from '表名' order by '字段名' desc
取消 评论
Oracle查询最大的3个值的两种方法
第一种:
select x, rownum r
from
(
select x
from t
order by x desc
)
where rownum = 3;

第二种:
select x
from
(
select x, row_number() over ( order by x desc ) r
from t
)
where r = 3;
取消 评论
k=max(a,[],2)%a矩阵的行最大值,每行的一起就出来了。L=max(a)%a矩阵的列最大值,每一列的。R=sum(k)%计算每行最大值的和C=sum(L) %计算每列最大值的和需要计算的矩阵很多,就把这几行程序写个循环。
取消 评论
ZOL问答 > 相机 > 其他分类 > 求一SQL语句:怎么查询最大的前3个值

举报

感谢您为社区的和谐贡献力量请选择举报类型

举报成功

经过核实后将会做出处理
感谢您为社区和谐做出贡献

扫码参与新品0元试用
晒单、顶楼豪礼等你拿

扫一扫,关注我们
提示

确定要取消此次报名,退出该活动?