在MySql中查询语法错误

时间:2015-04-07 07:33:23

标签: mysql sql

这是我的查询,它在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 

有人可以帮我解决这个问题吗?

2 个答案:

答案 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