这是我的查询,它在MySql中给出了SQL手动语法错误。
select
count(case when v.created_at = vv.minva then user_id) as num_new_users
from bills v
join (select user_id, min(created_at) as minva from bills t group by user_id ) vv
on v.user_id = vv.user_id
有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
您忘记在CASE声明中使用end
。
select
count(case when v.created_at = vv.minva then user_id end) as num_new_users
from bills v
join (select user_id, min(created_at) as minva from bills t group by user_id ) vv
on v.user_id = vv.user_id
答案 1 :(得分:1)
case statement
应以end
select
count(case when v.created_at = vv.minva then user_id end ) as num_new_users
from bills v
join (select user_id, min(created_at) as minva from bills t group by user_id ) vv
on v.user_id = vv.user_id