COUNT(DISTINCT(查找函数不是列时的情况?MySQL

时间:2014-01-23 19:41:49

标签: mysql syntax

确定。我即将放弃这个。

当我运行以下查询时,我得到“错误代码:1305。FUNCTION statpurchase.playerId不存在”。我没有获得行号,但我强烈怀疑COUNT(DISTINCT(WHEN条款。

该查询试图计算在一段时间内在给定日期内进行购买的唯一玩家ID的百分比。 statpurchase.playerId是一个有效的列名。

这是一个责备他的工具的穷人,但我怀疑它可能是一个类似于this one的解析器错误。

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$$

1 个答案:

答案 0 :(得分:3)

在这2行上你尝试使用statpurchase.playerId作为一个函数,它似乎不是,它是你表中的一列

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