简体   繁体   中英

Getting data from MySQL for every day of the week

I need to get stats from my site for every day of the week example.

    $str_sqlQuery = 'SELECT COUNT(DISTINCT (CASE WHEN (orders.status_id = 1
                       AND DAYOFWEEK(orders.datetime_ordered) = 1) THEN orders.id 
                                ELSE NULL END)) AS cnt_items_bought_sunday';

I am getting the count for every order made on a sunday where it was successfull. Would it be better to get the orders to PHP and count them there or continue it like this. I am trying it like this but it seems a little too resource intensive for my server.

First of all check your table was properly made (primary key and indexes used in the correct way, following standards), if it's not, fix that, thanks to that tiny standards you can get a great change in performance.

advice: Let the client (PhP) do the operative part(counting in this case, but operations in general)so you evade the memory hungry part from you sql query execution.

Hope this helps. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM