简体   繁体   English

每周每天从MySQL获取数据

[英]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. 将订单发送到PHP并在那里进行计数或像这样继续下去会更好。 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. 建议:让客户端(PhP)执行操作部分(在这种情况下为计数,但通常是操作),以便从sql查询执行中避开内存不足的部分。

Hope this helps. 希望这可以帮助。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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