Oxyrus
December 8, 2016, 1:15am
1
Hey there.
I would like to know what is the best approach to get data for specific dates, for instance, I want to create a chart displaying the users registered from Monday through Sunday, see screenshot below:
How would you guys structure your queries?
Thanks for your time.
Sounds like a normal aggregate, or you could get more fancy with a pivot query. Easier to show examples if you show all relevant schemas.
Oxyrus
December 8, 2016, 3:48pm
3
My schema is very basic, I have not added any date fields apart from the default ones (inserted_at, updated_at)
schema "movies" do
field :title, :string
field :description, :string
timestamps()
end
You’re basically looking at a SELECT DATE(inserted_at), count(*) GROUP BY DATE(inserted_at).
*Using proper syntax for the equivalent of DATE for your database of course.
2 Likes
brightball:
You’re basically looking at a SELECT DATE(inserted_at), count(*) GROUP BY DATE(inserted_at).
*Using proper syntax for the equivalent of DATE for your database of course.
Exactly, and Ecto syntax supports it too as I recall.
1 Like