mysql,只返回大于10000的结果

时间:2018-02-28 04:43:30

标签: mysql sql mysql-workbench

我正在比较两个表之间的绝对差异,四舍五入到最接近的数百个。我需要结果输出只显示大于10,000的值。我的输出包括较低的数字。这是我的代码:

select  ve.Geography, 
round(abs(ce.2010 - ve.2010), -2) as '2010', 
round(abs(ce.2011 - ve.2011), -2) as '2011', 
round(abs(ce.2012 - ve.2012), -2) as '2012', 
round(abs(ce.2013 - ve.2013), -2) as '2013', 
round(abs(ce.2014 - ve.2014), -2) as '2014', 
round(abs(ce.2015 - ve.2015), -2) as '2015' 
from ve join ce on ve.Geography = ce.Geography 
where 
ve.Geography = ce.Geography or
round(abs(ce.2010 - ve.2010), -2)>= 10000 or
round(abs(ce.2011 - ve.2011), -2)>=10000 or 
round(abs(ce.2012 - ve.2012), -2)>=10000 or
round(abs(ce.2013 - ve.2013), -2)>=10000 or
round(abs(ce.2014 - ve.2014), -2)>=10000 or
round(abs(ce.2015 - ve.2015), -2)>=10000
;

1 个答案:

答案 0 :(得分:1)

这是你的问题:

where ve.Geography = ce.Geography

对于结果集中的每个匹配联接记录,这将始终返回true。删除它,查询应该工作:

WHERE
    ROUND(ABS(ce.2010 - ve.2010), -2) >= 10000 OR
    ROUND(ABS(ce.2011 - ve.2011), -2) >= 10000 OR
    ROUND(ABS(ce.2012 - ve.2012), -2) >= 10000 OR
    ROUND(ABS(ce.2013 - ve.2013), -2) >= 10000 OR
    ROUND(ABS(ce.2014 - ve.2014), -2) >= 10000 OR
    ROUND(ABS(ce.2015 - ve.2015), -2) >= 10000