1
lichao Oct 17, 2014 select a, b, case when a/b > 0.5 then 5 when a/b > 0.3 then 4 when a/b > 0.12 then 3 else 0 end as score
|
4
tobyzw Oct 17, 2014 select a, b, case when a/b > 0.5 then 5 when a/b > 0.3 then 4 when a/b > 0.12 then 3 else 0 end as score
------------------------- 可能会有问题,a/b可能会出异常,b=0的情况需要考虑进去 |
6
ozking Oct 17, 2014 用a > 0.5*b 会不会效率高一点?
|
13
frye Oct 17, 2014
SELECT
a, b, IF( a / b > 0.12, IF( a / b > 0.18, IF( a / b > 0.3, 5, 4 ), 3 ), 0 ) AS score FROM table_name |
14
cye3s Oct 17, 2014 via Android 子查询查一次a/b,外面套case
|
15
frye Oct 17, 2014 INSERT INTO TEST_A (account_id, profit_rate, score) SELECT
account_id, IF ( init_funds > 0, profit / init_funds, 0 ) AS profit_rate, IF ( IF ( init_funds > 0, profit / init_funds, 0 ) > 0.12, IF ( IF ( init_funds > 0, profit / init_funds, 0 ) > 0.18, IF ( IF ( init_funds > 0, profit / init_funds, 0 ) > 0.3, 5, 4 ), 3 ), 0 ) AS score FROM TEST_B |
18
frye Oct 17, 2014 INSERT INTO TEST_A (account_id, profit_rate, score) SELECT
TEST_B.account_id, TEST_B.profit_rate, IF ( TEST_B.profit_rate > 0.12, IF ( TEST_B.profit_rate > 0.18, IF (TEST_B.profit_rate > 0.3, 5, 4), 3 ), 0 ) AS score FROM ( SELECT IF ( init_funds > 0, profit / init_funds, 0 ) AS profit_rate, account_id FROM TEST_B ) AS TEST_B |
20
viquuu Oct 17, 2014 select a,b,
case when c > 0.5 then 5 when c > 0.3 then 4 when c > 0.12 then 3 else 0 end as score from ( select a,b, a/isnull(b,1) as c from test ) |