它会有点复杂。但我想保持简单。
我想查询条件如下
dsponserid
喜欢我的身份'2018-02-13' AND NEXT 7 DAYS
这是由我完成的。但现在卡在哪里是我想要user count
哪个通过上面的结构高于5而不是结果应该是200我将返回0
我使这个查询无法正常工作
SELECT
CASE
WHEN
count(
SELECT * FROM `mlm_register`
WHERE dsponserid = 10001
AND `joindate` BETWEEN '2018-02-13' AND DATE_ADD('2018-02-13', INTERVAL 7 DAY)
) >= 5
THEN
IF(
dsponserid = 10001
AND `joindate` BETWEEN '2018-02-13' AND DATE_ADD('2018-02-13', INTERVAL 7 DAY), 200, 0
)
AS MONEY
FROM `mlm_register`
简单说明:
通过WHERE dsponserid = 10001 AND
joindate BETWEEN '2018-02-13' AND DATE_ADD('2018-02-13', INTERVAL 7 DAY)
的用户数超过5因此,如果用户数低于5,我将返回输出 200其他我将返回零(0)
我希望我的解释更好。!
答案 0 :(得分:1)
您可以修复语法错误:
SELECT (CASE WHEN (SELECT COUNT(*)
FROM mlm_register r2
WHERE r2.dsponserid = 10001 AND
r2.joindate >= '2018-02-13' AND
r2.joindate < DATE_ADD('2018-02-13', INTERVAL 8 DAY)
) < 5
THEN 0
WHEN r.dsponserid = 10001 AND
r.joindate >= '2018-02-13' AND
r.joindate < DATE_ADD('2018-02-13', INTERVAL 8 DAY)
THEN 200
ELSE 0
END) AS MONEY
FROM mlm_register r
我不确定这是否有用。
注意:
COUNT()
的参数。between
用于日期,因为如果日期确实是日期/时间,则会出现意外行为。IF()
,因为CASE
是ANSI标准SQL。如果你这样做,不要混合两种类型的条件表达式。这只会使查询更难以遵循。答案 1 :(得分:0)
SELECT DISTINCT
IF(
(SELECT COUNT(*)
FROM mlm_register r2
WHERE r2.dsponserid = 10001
AND r2.joindate BETWEEN '2018-02-13' AND DATE_ADD('2018-02-13', INTERVAL 7 DAY) ) >= 5,
200,
0
)
AS TotalVal
FROM mlm_register r
我需要的是
for each (i in rankTable){
ranking.push(dashboard.getRange(2,i+9).getValue()); //this line is the problem
i++;
}
while (dashboard.getRange(2,i+9).getValues() != '') {
ranking.push(dashboard.getRange(2,i+9).getValue()); //same problem here
i++;
}