user1932914
user1932914

Reputation: 186

SQL Datetime query

Given a database, having table named as users with id and created_at field. Id is smallint type and created_at is datetime type.Want to know the people registered for every month.

The database am using is SQLite.

Wrote this simple query which supposed to be working but it gives an error. Could you please help me out.

select count(id) as Orders, DATEPART(mm,created_at) AS Ordermonth
from users
Group by DATEPART(mm,created_at);

Upvotes: 1

Views: 222

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269563

The equivalent in SQLite would look like:

Select count(id) as Orders, strftime('%Y-%m', created_at) AS Ordermonth
From users
Group by strftime('%Y-%m', created_at)
Order by Ordermonth;

Your code looks like SQL Server code.

Upvotes: 3

Related Questions