簡體   English   中英

COUNT(DISTINCT(在尋找函數而不是列的情況下?

[英]COUNT(DISTINCT(CASE WHEN looking for function not column? MySQL

好。 我要放棄這一點。

當我運行以下查詢時,出現“錯誤代碼:1305。FUNCTIONstatpurchase.playerId不存在”。 我沒有行號,但我強烈懷疑COUNT(DISTINCT(WHEN子句。

該查詢正在嘗試計算在給定的時間內進行購買的唯一玩家ID的百分比。 statpurchase.playerId是有效的列名。

這是一個可憐的人,責怪他的工具,但我懷疑它可能是類似於錯誤的解析器錯誤。

delimiter $$
CREATE PROCEDURE `percentUniquesPurchasing`(in startTime datetime, in endTime datetime, in placeId int)
BEGIN

declare total_uniques int;
declare iOS_uniques int;
declare desktop_uniques int;
declare i datetime;
set i = startTime;

CREATE TEMPORARY TABLE results (
    theday datetime, 
    total float,
    iOS float,
    desktop float
);



while(i < endTime + INTERVAL 1 DAY) do



    select count(distinct(statplaysession.playerId)), 
        count(distinct(case when touchInterface = 1 then statplaysession.playerId else null end)),
        count(distinct(case when touchInterface = 0 then statplaysession.playerId else null end))
    into
        total_uniques, iOS_uniques, desktop_uniques
    from rbxstats.statplaysession 
    where
        statplaysession.start > i and
        statplaysession.start < i + INTERVAL 1 DAY and
        statplaysession.placeId = placeId;

    insert into results (theday, total, iOS, desktop) 
    select i, 
            if(total_uniques > 0, count(distinct(statpurchase.playerId)) / total_uniques, 0), 
            if(iOS_uniques > 0, count(distinct(statpurchase.playerId(case when touchInterface = 1 then statpurchase.playerId end))) / iOS_uniques, 0), 
            if(desktop_uniques > 0, count(distinct(statpurchase.playerId(case when touchInterface = 0 then statpurchase.playerId end))) / desktop_uniques,0)
    from rbxstats.statpurchase where
        statpurchase.timestamp > i and
        statpurchase.timestamp < i + INTERVAL 1 DAY and
        statpurchase.placeId = placeId;


    set i = i + INTERVAL 1 DAY;
end while;

select * from results;
drop temporary table results;
END$$

在這兩行中,您嘗試將statpurchase.playerId用作一個函數(看起來似乎不是),它是表中的一列

 if(iOS_uniques > 0, count(distinct(statpurchase.playerId(case when 
 if(desktop_uniques > 0, count(distinct(statpurchase.playerId(case when 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM