Skip to content
Advertisement

mysql best way to count orders ordered by status

For my panel I update my “status-buttons” with count-numbers.

F.e. New 2, backorder 5, cancelled 3, shipped 201

In the back, I now count them like this:

JavaScript

I know… “Use prepared statements”… I will, in the updated version of my script 🙂

But is there an easier way to get all the orders from that specific user and then just receive the amount per “status”?

I already tested the below, but in the average, the difference is 0.000024 vs 0.000034. So it is faster, but I think (and hope) there is a better way?

JavaScript

Also, the upper way is not that usefull when there would be new statusses available (12,13,…).

Advertisement

Answer

You can use group by when status value is dynamic

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement