oracle ,mysql总date的比较

date类型时间格式不同,是不相等的.哪怕是通一天 同一时刻。

以下是MYSQL:

格式相同的时候:

select 
str_to_date('2011-09-21','%Y-%m-%d')
=
str_to_date('2011-09-21','%Y-%m-%d')
as
rel

结果:

 格式不相同的时候:

select 
str_to_date('2011-09-21','%Y-%m-%d')
=
str_to_date('2011-09-21','%d-%m-%y')
as
rel

结果:

所以:

select   D_JYSJ,  sum(N_JE)  FROM 
K0001_WORK_JYMX_T
where
1=1
and
D_JYSJ = to_date('2011-09-13','yyyy-mm-dd')
or
D_JYSJ = to_date('2011-09-14','yyyy-mm-dd')
group by
D_JYSJ

要改成

select   D_JYSJ,  sum(N_JE)  FROM 
K0001_WORK_JYMX_T
where
1=1
and
to_char(D_JYSJ,'yyyy-mm-dd')
in
(
'2011-09-13',
'2011-09-14'
)
group by
D_JYSJ







posted @ 2011-09-21 13:14  liheping  Views(3761)  Comments(0Edit  收藏  举报