0

我有以下查询需要从 Oracle 移植到 MySQL。它在两者中执行时都没有任何编译错误,但结果表不同。在 Oracle 中,我得到每个计数列下的单个计数。但是在 MySQL 中,无论计数应该在哪里,它们都落在 a5 以下。像这样:

在甲骨文中:在此处输入图像描述

但在 MySQL 中:在此处输入图像描述

select x1.alert_level, count(x1.a1),  count(x1.a2), count(x1.a3), 
count(x1.a4), count(x1.a5) from 
(select  
table_name.column_name alias, 
case when (now() - column_name) <= 7 then 1 end as a1,  
case when (now() - column_name) between 7 and 30 then 1 end as a2, 
case when (now() - column_name) between 30 and 60 then 1 end as a3,
case when (now() - column_name) between 60 and 90 then 1 end as a4, 
case when (now() - column_name) >= 90 then 1 end as a5 
FROM tables
WHERE filter_conditions)  x1  GROUP BY x1.alias;

如何调和差异以使 MySQL 输出看起来像 Oracle 输出?感谢您的帮助!

4

1 回答 1

1

我用过datediff,效果很好!

于 2013-03-04T02:56:40.797 回答