Pure SQL Query in Rails to get customers in last 30 days
I would normally just use:
ShopifyAPI::Customer.where("created_at > ?", 30.days.ago).count
But I am getting this error
ArgumentError: wrong number of arguments (2 for 0..1)
So I am trying to write a pure SQL query:
ShopifyAPI::Customer.where("created_at > DATEADD(day, -30, getdate())").count
But getting this error:
ArgumentError: expected a clauses Hash, got "created_at > DATEADD(day, -30, getdate())"
Any ideas on how to get the customer count from last 30 days?
In Postgres, the
where clause would look like:
ShopifyAPI::Customer.where("created_at > CURRENT_DATE - interval '30 day' ").count
The syntax you are using is SQL Server syntax.
Just edit your first code like:
ShopifyAPI::Customer.where(["created_at > ?", 30.days.ago]).count
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.