2

I want alternative supabase code for this SQL command

SELECT order_date,COUNT(*) as count
FROM orders
GROUP BY order_date
ORDER BY order_date Desc;

What I am trying to do is, I want the number of orders of each day. This is how my table looks likeenter image description here

Since I am using supabase, I don't find any alternative for group by query. Can anyone please help?

Hadi azeez
  • 89
  • 3
  • 10
  • 1
    Remember you can always make a stored procedure (function) that contains the SQL you want if you can't figure out how to do it with the API. It's often quicker to do it that way for one-off things. – Shorn Apr 30 '21 at 10:31
  • 2
    Doing a group and count at the same time is not supported via supabase-js yet. As others mentioned create a view or stored proceedure first and then query it via supabase-js – everconfusedGuy Apr 30 '21 at 14:30

1 Answers1

3

Add this to a view or stored procedure, then it can be called via the API supabace.rpc()

Hadi azeez
  • 89
  • 3
  • 10