0
用户kWEye3931 Lv5 初级互助 发布于2020-6-3 12:25
select * from ( select task_level , content_task , planned_deliverables , those_responsible , completion_date , actual_completion_date , task_create_day , this_week_state , remaining_days , task_reply_added , row_number() over (partition by number2 order by tasks_reporting_day desc) rn from NEW_REPORT.TASK_MAINTENANCE ) t where t.rn<=1
0
snrtuemc Lv8 专家互助 发布于2020-6-3 09:26(编辑于 2020-6-3 12:47)
select * from ( select last_comment, row_number() over(partition by employeeid,roadline,stationname order by logindate desc) rn from reocrd ) t where t.rn <=3
这段的意思是,将reocrd表根据员工工号( employeeid),线路(,roadline),站点名称(stationname)分组后,取登录日期(logindate) 最大的三行的last_comment的值.
select * from (select task_level , content_task , planned_deliverables , those_responsible , completion_date , remaining_days , actual_completion_date , task_create_day , this_week_state , remaining_days , task_reply_added , tasks_reporting_day , task_reply_added , tasks_reporting_day,row_number() over (partition by number2 order by tasks_reporting_day desc) rn from "NEW_REPORT"."TASK_MAINTENANCE" ) t where t.rn<=3
用户kWEye3931(提问者)
- select * from
(select
task_level ,
content_task ,
planned_deliverables ,
those_responsible ,
completion_date ,
remaining_days ,
actual_completion_date ,
task_create_day ,
this_week_state ,
remaining_days ,
task_reply_added ,
tasks_reporting_day ,
task_reply_added ,
tasks_reporting_day
over (partition by number2 ,order by tasks_reporting_day desc) rn
from \"NEW_REPORT\".\"TASK_MAINTENANCE\"
) t
where t.rn<=3
我这个有啥错吗?
snrtuemc 回复 用户kWEye3931(提问者)
- 看修改答案,Oracle中row_number() over是一个函数
用户kWEye3931(提问者) 回复 snrtuemc
- 报错缺失表达式
snrtuemc 回复 用户kWEye3931(提问者)
- 把row_number() over前面的字段放进over函数内
取消
评论
0
用户20462883 Lv4 见习互助 发布于2020-6-3 09:43
概念有点模糊,但我做过类似的,比如下方的SQL是实现分组后取每个分组的最大值,总共取前30条,也就是每个分组只取其中一条且是最大的那条数据:
select * from (
select a.variety ,
to_char(to_date(a.in_store_date,'yyyy-mm-dd hh24:mi:ss'),'yyyy') 年份,
max(ceil((to_date(nvl(a.out_store_date,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')), 'yyyy-mm-dd hh24:mi:ss') - To_date(a.in_store_date , 'yyyy-mm-dd hh24:mi:ss')))) 周转天数
from DWD_STOCK_01_N_2020 a
group by a.variety,to_char(to_date(a.in_store_date,'yyyy-mm-dd hh24:mi:ss'),'yyyy')
order by max(ceil((to_date(nvl(a.out_store_date,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')), 'yyyy-mm-dd hh24:mi:ss') - To_date(a.in_store_date , 'yyyy-mm-dd hh24:mi:ss')))) DESC
)
where rownum <= 30