hive col计数时不能选择大小写

uqxowvwt  于 2023-11-18  发布在  Hive
关注(0)|答案(2)|浏览(198)

这是我写的SQL查询:

SELECT
    COUNT(*) AS TOTLA_COUNT,  
    COUNT(
        CASE
            WHEN ( market_val > 0 AND ABS( loan_amt / market_cal * 100 - ratio ) > 5 ) THEN 1
            ELSE NULL
        END
    ) AS FAIL_COUNT,  
    COUNT( FAIL_COUNT / TOTAL_COUNT * 100 ) AS FAIL_RATE  
FROM
    MY_TABLE

字符串
但我得到一个错误
错误原因是无法解析给定输入列的“market_瓦尔”
我能知道怎么修吗?谢谢

uujelgoq

uujelgoq1#

FAIL_NAME和TOTLA_NAME是您不能对其执行操作的别名。

xj3cbfub

xj3cbfub2#

别的办法了
原样:

SELECT
    COUNT(*) AS TOTLA_COUNT,  
    COUNT(
        CASE
            WHEN ( market_val > 0 AND ABS( loan_amt / market_cal * 100 - ratio ) > 5 ) THEN 1
            ELSE NULL
        END
    ) AS FAIL_COUNT,  
    COUNT( FAIL_COUNT / TOTAL_COUNT * 100 ) AS FAIL_RATE  
FROM
    MY_TABLE

字符串
目标:

SELECT a.TOTLA_COUNT, a.FAIL_COUNT
  , FAIL_COUNT / TOTAL_COUNT * 100 AS FAIL_RATE  
FROM (
  SELECT
      COUNT(*) AS TOTLA_COUNT,  
      COUNT(
          CASE
              WHEN ( market_val > 0 AND ABS( loan_amt / market_cal * 100 - ratio ) > 5 ) THEN 1
              ELSE NULL
          END
      ) AS FAIL_COUNT
  FROM
      MY_TABLE
) a

相关问题