我有以下查询,我需要从Oracle移植到MySQL。它执行时两者都没有任何编译错误,但结果表不同。在Oracle中,我获得每个计数列下的单个计数。但是在MySQL中,无论计数在哪里,它们都会降到a5以下。像这样:
在Oracle中:
但在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输出?谢谢你的帮助!
答案 0 :(得分:1)
我使用datediff
并且效果很好!