1, grade name time
2,一年级 张三 1:00
3,一年级 张三 2:00
4,一年级 王五 3:00
5,一年级 王五 3:30
6,二年级 李四 4:00
7,二年级 李四 5:00要显示3,5,7行记录怎么写这个sql?要能在pl/sql中运行
2,一年级 张三 1:00
3,一年级 张三 2:00
4,一年级 王五 3:00
5,一年级 王五 3:30
6,二年级 李四 4:00
7,二年级 李四 5:00要显示3,5,7行记录怎么写这个sql?要能在pl/sql中运行
where rcn in (3,5,7);
with tb as(
select '一年级' grade,'张三' name,to_date('1:00','hh24:mi') time from dual union all
select '一年级', '张三',to_date('2:00','hh24:mi') from dual union all
select '一年级', '王五',to_date('3:00','hh24:mi') from dual union all
select '一年级', '王五',to_date('3:30','hh24:mi') from dual union all
select '二年级', '李四',to_date('4:00','hh24:mi') from dual union all
select '二年级', '李四',to_date('5:00','hh24:mi') from dual)
--以上为提供数据的语句
select grade,name,to_char(time,'hh24:mi')
from tb t1
where not exists(select 1 from tb t2
where t1.grade=t2.grade
and t1.name=t2.name
and t1.time<t2.time)GRADE NAME TO_CH
------ ---- -----
二年级 李四 05:00
一年级 张三 02:00
一年级 王五 03:30