首页 \ 问答 \ MySQL,获取一周中所有日子的平均值(MySQL, get averages for all days of the week)

MySQL,获取一周中所有日子的平均值(MySQL, get averages for all days of the week)

我有一个表格,其中包含我所在位置不可用或免费的每小时存储的数据。 我当前的查询获得一整天的平均入住/免费点数:

SELECT AVG(sz.occupied), AVG(sz.free)
FROM `hourly_cache` AS sz
WHERE   sz.time BETWEEN '2017-01-01 00:00:00' AND '2017-01-02 00:00:00'
        AND HOUR(sz.time) BETWEEN 8 AND 22
        AND libID = 0

但是,如果我想要的不仅仅是这一天的平均值,而是一周中的其他每一天呢? 说:我想要本周一的平均值加周二,周三等。

我如何循环每天和每天根据它的日期运行此查询?

我想在PHP中这样做,但想知道是否有一种方法适用于MySQL?


I have a table that contains data stored for every hour a spot in my location is unavailable or free. My current query gets the average occupancy / free spots of an entire day:

SELECT AVG(sz.occupied), AVG(sz.free)
FROM `hourly_cache` AS sz
WHERE   sz.time BETWEEN '2017-01-01 00:00:00' AND '2017-01-02 00:00:00'
        AND HOUR(sz.time) BETWEEN 8 AND 22
        AND libID = 0

But what if I want the average for not just this day, but every other day of the week? Say: I want the average for Monday of this week, plus Tuesday, Wednesday, etc.

How do I loop through each day and on each day run this query based on what day it is?

I was thinking of doing it in PHP but was wondering if there's an approach that works in MySQL?


原文:https://stackoverflow.com/questions/51352827
更新时间:2022-11-05 09:11

最满意答案

您正在从流中读取两次但只写一个缓冲区。 改变这个:

count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, responseStream.Read(buffer, 0, buffer.Length));

对此:

count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);

You are reading twice from the stream but only writing one buffer. Change this:

count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, responseStream.Read(buffer, 0, buffer.Length));

To this:

count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);

相关问答

更多
  • // loading bytes from a file is very easy in C#. The built in System.IO.File.ReadAll* methods take care of making sure every byte is read properly. byte[] bytes = System.IO.File.ReadAllBytes("myfile.pdf"); // munge bytes with whatever pdf software you wan ...
  • 您只需将PDF文件读入字节数组即可: byte[] bytes = System.IO.File.ReadAllBytes(pathToFile); You can simply read the PDF file into a byte array: byte[] bytes = System.IO.File.ReadAllBytes(pathToFile);
  • 使用Base64方法将byte []转换为String并将其解码回byte [] public static byte[] decode(String encoded) public static String encode(byte[] binaryData) { Use Base64 methods to convert byte[] to String and decode it back to byte[] public static byte[] decode(String encoded) p ...
  • 您正在从流中读取两次但只写一个缓冲区。 改变这个: count = responseStream.Read(buffer, 0, buffer.Length); memoryStream.Write(buffer, 0, responseStream.Read(buffer, 0, buffer.Length)); 对此: count = responseStream.Read(buffer, 0, buffer.Length); memoryStream.Write(buffer, 0, count); ...
  • 我无法用当前的实现解决关闭MemoryStream的问题,所以我不得不完全重构。 相反,我使用本文所述的PdfFileEditor.Concatenate()方法。 我的实施如下: public byte[] GetPrintContent(List models) { PdfFileEditor pdfEditor = new PdfFileEditor(); MemoryStream ...
  • 我建议在控制器上创建另一个专门用于渲染PDF数据的操作 。 然后,只需在data属性中引用它: data="@Url.Action("GetPdf", "PDF")" 我不确定您是否可以在DOM中转储原始PDF数据而不会遇到某种编码问题。 尽管我从未尝试过,但您可能会像图像一样。 但是,为了演示,图像看起来像: src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" 因此, 假设可以做同样的 ...
  • 当我将流转换回PDF时文档显示为空白的原因是当使用document.Save(memoryStream, false); ,有必要调用document.Close(); 之后,即: document.Save(memoryStream, false); document.Close(); The reason the document was appearing blank when I converted the stream back to a PDF is that when using docum ...
  • 每个收到的文件都可以使用相同的名称存储(我使用“my.pdf”),然后存储太多文件的风险。 如果需要缓存文件,则可以指定不同的名称。 尽管我尝试了ms-appdata,但pdf查看器不想显示Local,Temp或Downloads文件夹中的文件,因此我不得不将文件从Local文件夹移动到Assets以显示查看器“想要”它的方式,通过ms- APPX-网络。 下载文件夹也存在CreationCollisionOption.ReplaceExisting的问题,如果文件已存在而不是替换它,则说无效参数,但Loc ...
  • 您可以使用Apache commons ,这在任何Java项目IMO中都是必不可少的。 然后你可以使用FileUtils的readFileToByteArray(File file)和writeByteArrayToFile(File file, byte[] data) 。 (这里是commons-io,这是FileUtils的地方: http : //commons.apache.org/proper/commons-io/download_io.cgi ) 例如,我在这里尝试了这个并且它工作得非常好。 ...
  • 有两个问题: Word互操作程序集通常无法写入除磁盘之外的其他源。 这主要是因为SDK是基于UI的SDK,它并不意味着做背景,因为它高度依赖于UI。 (实际上,它只是UI应用程序的包装器,而不是它背后的逻辑层) 您不应该在ASP.NET上使用Office互操作程序集。 阅读Office的服务器端自动化的注意事项 ,其中说明: Microsoft目前不推荐也不支持任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)的Microsoft Office应用程序自动化,因为O ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。