1
SELECT 
        SUM (
            CASE
                WHEN pop.usertype=1 THEN pop.useramount
                WHEN pop.usertype=2 THEN 0-pop.useramount
            END )        
    FROM
        popular pop
;

我如何将此语句转换为 DECODE 函数?

我已经尝试过这个(和其他轻微的变化) - 但我似乎总是得到不同的结果..

SELECT 
        SUM (
            DECODE(pop.usertype,'1', 'pop.useramount',
                                '2', '0-pop.useramount')
            )        
    FROM
        popular pop
;

我试图更好地理解 DECODE 功能,但我真的很困惑为什么这不起作用?

4

1 回答 1

1

尝试删除'如下

SELECT 
        SUM (
            DECODE(pop.usertype,'1', pop.useramount,
                                '2', 0-pop.useramount)
            )        
    FROM
        popular pop
;
于 2013-07-02T08:50:42.497 回答