2017-08-29 47 views
0

在下面查詢的,我不能夠使用1111(HY000):無法使用組功能|無法使用組功能THEN欄目查詢

THEN count(DISTINCT(workflow_link.email_api_response_packets.parent_id)) 

語法,任何幫助,在此表示讚賞。

SELECT workflow_link.email_api_response_packets.subscriber_id 
    , count(DISTINCT(workflow_link.email_api_response_packets.parent_id)) as cnt 
    , SUM(CASE WHEN (workflow_link.email_api_response_packets.action = 'O' 
         AND workflow_link.email_api_response_packets.parent_id IS NOT NULL 
       THEN count(DISTINCT(workflow_link.email_api_response_packets.parent_id)) 
       ELSE 0 
       END)*100/SUM(CASE WHEN (workflow_link.email_api_response_packets.id 
             AND workflow_link.email_api_response_packets.parent_id IS NULL) 
            THEN 1 
            ELSE 0 
            END) AS percentage 
FROM workflow_link.email_api_response_packets 
WHERE workflow_link.email_api_response_packets.updated_at >= 1403929223 
    AND workflow_link.email_api_response_packets.updated_at <= 1503929479 
    AND workflow_link.email_api_response_packets.list_id IN (400) 
    AND workflow_link.email_api_response_packets.is_test = 0 
GROUP BY workflow_link.email_api_response_packets.subscriber_id 
HAVING percentage >= 0 
+0

你試過計數(DISTINCT工作流程...)嗎? (即沒有內部支架) – etsa

+0

在第一個「CASE WHEN」時出現括號問題:在WHEN部分之後打開它,但在END之後關閉它。所以在'IS NOT NULL'之後缺少一個括號。 – waka

+0

@etsa,謝謝你的評論我已經試過建議的方式,但沒有運氣同樣的錯誤 – Abhishek

回答

0

試試這個。我也刪除了所有不必要的括號。

SUM(CASE WHEN workflow_link.email_api_response_packets.action = 'O' 
       AND workflow_link.email_api_response_packets.parent_id IS NOT NULL 
     THEN count(DISTINCT workflow_link.email_api_response_packets.parent_id) 
     ELSE 0 END 
    ) * 100 
    /SUM(CASE WHEN workflow_link.email_api_response_packets.id 
         AND workflow_link.email_api_response_packets.parent_id IS NULL 
       THEN 1 
       ELSE 0 END) AS percentage 
+0

它不工作,謝謝你的回答 – Abhishek

+0

我認爲你不能做構造SUM(COUNT(..))。所以你必須重寫你的查詢。如果您使用創建/插入腳本和類似的查詢發佈更簡單的結構,我可以嘗試幫助您。 – etsa

相關問題