表T中,有A,B,C,D四个字段,用于存放时间,数据设计时,是VARCHAR2类型
如:
A B C D
2008-07-29 2008-03-11 2007-05-25 2008-01-24请问,如何写一条SQL语句,能得到 A,B,C,D 时间值中最小的值。
如上例中,即是 2007-05-25 。
如:
A B C D
2008-07-29 2008-03-11 2007-05-25 2008-01-24请问,如何写一条SQL语句,能得到 A,B,C,D 时间值中最小的值。
如上例中,即是 2007-05-25 。
解决方案 »
- oracle10g 在win7 64 上安装
- 在统计数据时候 经常遇到 这样的问题 ,有没有好的办法 ?................
- 请教各位一句SQL语句
- 100分请教如何读取blob类型数据到指定路径?
- 安装oracle9i企业版后进行数据库配置提示insufficient privileges
- 存储过程中不能使用select 吗?
- 不安装ORACLE客户端访问ORACLE数据库的方法
- 请教一下,什么可视化工具可以方便开发pro*c
- 各位高手,请问在ORACLE中的哪个包可以执行外部命令(比如作备件)?
- ORA-07445: exception encountered: core dump [kokscold()+719] [SIGSEGV] [ADDR:0x5
- SQL Server与Oracle的函数区别
- 事务中不提交或不回滚会造成连接上的内存泄漏吗?
from(
select to_date(A,'yyyy-mm-dd') a
union all
select to_date(B,'yyyy-mm-dd') a
union all
select to_date(C,'yyyy-mm-dd') a
union all
select to_date(D,'yyyy-mm-dd') a
)
select min(aa) from (
select to_date(a,'yyyy-mm-dd') as aa from table union
select to_date(b,'yyyy-mm-dd') from table union
select to_date(c,'yyyy-mm-dd') from table union
select to_date(d,'yyyy-mm-dd') from table
)
(
(select A from T)
union all
(select B from T)
union all
(select C from T)
union all
(select D from T)
)
;
另外。
如果要写 WHERE语句C ,select A from T where C
是不是要写成
select min(A) from
(
(select A from T where C)
union all
(select B from T where C)
union all
(select C from T where C)
union all
(select D from T where C)
)
;???
这样写好繁琐啊,有没有更简便的写法??
如果表中就一条记录,我的写法没有问题。
select LEAST(a,b,c,d) from tablename ;
如果表中有多条记录,并且你要取所有记录的最小值,那就在最外面加上一个min()函数。
select min(LEAST(a,b,c,d)) from tablename ;btw: guoxiaoshou2000说的对,'yyyy-mm-dd'格式下,不用to_date效果是一样。