adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.03k stars 189 forks source link

Get users count in last year group by month | lucid | postgres | cockroachDb #913

Closed dmostafiz closed 1 year ago

dmostafiz commented 1 year ago

This is actually not an issue!

Hello @thetutlage

I wasn't able to find any discussion section or a way to reach you. that's why I've opened the issue here. I really need help.

Please take a bit of time for me,

my query is

I need to show user registrations every month for the last year. I did this query in Laravel eloquent but didn't find a solution for how to do this query in Lucid. Please note! I'm using PostgreSQL and cockroach db

I need somehow,, group users count by ( created_at---> month name ) for last year

User Table


id ----- username ---- email ---- created_at ---- updated_at


Raw query would be something like that ----> for postgreSQL

SELECT to_char(date_trunc('month', created_at), 'YYYY, Month') AS created_month, COUNT(id) AS total_registrations, FROM users GROUP BY date_trunc('month', created_at) ORDER BY date_trunc('month', created_at)


But I really need to know how I can do this using Lucid ORM

I'll appreciate any help from you. Best regards!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.