我需要为下面的情况找到最好的两个算术表达式,但它仅返回第一个表达式的结果。在两个中没有得到最大的。请提出任何建议。
SELECT greatest((((Received*8) + (Received*56))/(1000*900*64000*900)),
(((Transmitted*8) + (Transmitted*56))/(1000*900*64000*900))) AS Greatest_value
FROM Table_name
我得到的结果:第一个表达式的算术exp结果
答案 0 :(得分:3)
由于两个值的乘数相同,因此您可以将代码简化为:
SELECT GREATEST( Received, Transmitted ) * ( (8+56)/(1000*900*6400*900) )
AS Greatest_value
FROM table_name
或者只是:
SELECT GREATEST( Received, Transmitted ) / 810000000000
AS Greatest_value
FROM table_name
除此之外,您还需要检查数据:
SELECT COUNT( CASE WHEN Received >= Transmitted THEN 1 END ) AS received_greater,
COUNT( CASE WHEN Received < Transmitted THEN 1 END ) AS transmitted_greater
FROM table_name;