1

Here is my query and it's giving SQL manual syntax error in MySql.

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 

Can someone please help me with the problem?

1
  • The case is not correct. Commented Apr 7, 2015 at 7:33

2 Answers 2

2

You forgot to use end in CASE statement.

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 
Sign up to request clarification or add additional context in comments.

Comments

1

The case statement should be ended with 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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.