Can you please post a link to the project you are talking about? There is a lot of content on Codecademy and even if we know which career path, it can take us volunteers quite some time to find the exact project/exercise if you don’t provide a link in your post.
The project is called RPA Customer Segmentation. It is in the Data Scientist Career Path under SQL Challenge Projects.
I’m specifically working on Question 8 of that Challenge Problem which states “One of the members of the marketing team had an idea of calculating how old users were when they signed up”
Hopefully that helps but if I can offer more specific info let me know!
Any chance you could directly link the lesson, i.e. copy/paste the address. Hunting down specific projects through cc’s catalogue can be quite difficult.
The only project I noted with a similar title has only 7 tasks to complete.
Here is the link. The 8th Challenge question isn’t on the left side like normal. It is in the terminal window at the very bottom of the terminal. It is a comment as an extra challenge.
I’m in the same boat where I only saw 7 questions (if there was an eighth as a comment then I must’ve somehow missed it).
It’s worth noting that there’s no DATEDIFF in the sqlite docs (so avoid sinking time into trying it for this question) so unless there’s something I’m missing you’d need to work with the date in numerical form. I think I worked this one out with strftime but julianday is another option. Perhaps there’s a better route but I couldn’t spot one for sqlite.
Date calculations can be tricky. I tried using the strftime and julianday functions and they didn’t quite calculate the ages correctly. For example, the birthdate of 1982-04-17 came out to 39 years old instead of 38.
Finally, I got this to work:
select email, birthday, cast(strftime(’%Y.%m%d’, ‘now’) - strftime(’%Y.%m%d’, birthday) as int)
from users
limit 5;
Thanks everyone for your help! Ended up finding a video about strftime that really helped me and the code he helped explain was. @coffeencake your code is must quicker but I’m not familiar with the CAST clause yet haha
SELECT birthday,
CASE
WHEN strftime('%m', date('now')) > strftime('%m', date(birthday))
THEN strftime('%Y', date('now')) - strftime('%Y', date(birthday))
WHEN strftime('%m', date('now')) < strftime('%m', date(birthday))
THEN strftime('%Y', date('now')) - strftime('%Y', date(birthday)) - 1
WHEN strftime('%m', date('now')) = strftime('%m', date(birthday)) THEN
CASE
WHEN strftime('%d', date('now')) >= strftime('%d', date(birthday))
THEN strftime('%Y', date('now')) - strftime('%Y', date(birthday))
ELSE strftime('%Y', date('now')) - strftime('%Y', date(birthday)) - 1
END
END AS 'age'
FROM users;
I like the shorter formatting version with %Y.%m that I’d not come across. The only bit I’d note there is that the quote above mentions "how old users were when they signed up" so you may want to slightly alter the code to match that.