create table t(id int,age int) insert into t values(1,20) --a insert into t values(2,21) --b insert into t values(3,19) --c /* 如果a中的age大于b中的age就显示a数据否则显示b数据, 如果b中的age大于c中的age就显示b数据否则显示c数据。 */ select a.id, case when a.age>b.age then a.age else nvl(b.age,a.age) end as age from t as a left join t as b on a.id=b.id-1
id age ----------- ----------- 1 21 2 21 3 19
不知道是不是取最大值的意思?如果结果只有一条记录,如下:1) select max(T_T_AGE)from t_t 2) select T_T_ID ,T_T_AGE,rownum from( select T_T_ID ,T_T_AGE from t_t order by T_T_AGE desc) where rownum=1;
改一下数据: 1) select max(AGE)from t2) select ID ,AGE,rownum from( select ID ,AGE from t order by AGE desc) where rownum=1;
这样的话,题目的意思就是省略掉最小的age了,解法: select T_T_ID ,T_T_AGE from t_t where T_T_AGE not in ( select T_T_AGE from t_t where rownum=1 );
改一下数据: select ID ,AGE from t where AGE not in ( select AGE from t where rownum=1 );
也不是这样的啊 想想 如果b比a和c都大的话 那就要将b输出两遍了 对不 我的意见是:在如下表中: id age ----------- ----------- 1 18 2 21 3 19 select id,max(age) from 表 where id='1' or id='2' nuion select id,max(age) from 表 where id='2' or id='3' 因为表的记录很少 这样应该可以吧!
insert into t values(1,20) --a
insert into t values(2,21) --b
insert into t values(3,19) --c
/*
如果a中的age大于b中的age就显示a数据否则显示b数据,
如果b中的age大于c中的age就显示b数据否则显示c数据。
*/
select
a.id,
case when a.age>b.age then a.age else nvl(b.age,a.age) end as age
from t as a
left join t as b
on a.id=b.id-1
----------- -----------
1 21
2 21
3 19
select max(T_T_AGE)from t_t 2)
select T_T_ID ,T_T_AGE,rownum
from(
select T_T_ID ,T_T_AGE
from t_t
order by T_T_AGE desc)
where rownum=1;
1)
select max(AGE)from t2)
select ID ,AGE,rownum
from(
select ID ,AGE
from t
order by AGE desc)
where rownum=1;
select T_T_ID ,T_T_AGE
from t_t
where T_T_AGE not in
(
select T_T_AGE
from t_t
where rownum=1
);
select ID ,AGE
from t
where AGE not in
(
select AGE
from t
where rownum=1
);
想想 如果b比a和c都大的话 那就要将b输出两遍了 对不
我的意见是:在如下表中:
id age
----------- -----------
1 18
2 21
3 19
select id,max(age) from 表 where id='1' or id='2'
nuion
select id,max(age) from 表 where id='2' or id='3'
因为表的记录很少 这样应该可以吧!
至于数据相等的问题,题目种没有给出条件,既然没有给那我想就可以随便处理了(也 可以当做数据不相等来处理)。