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
最满意答案
您正在从流中读取两次但只写一个缓冲区。 改变这个:
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转换为字节(convert PDF to byte)[2022-09-25]
您只需将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); -
如何将PDF byte []转换为String和String转换为PDF byte [](How to convert PDF byte[] to String and String to PDF byte[])[2023-04-19]
使用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 ... -
将Byte []转换为PDF(Convert Byte [] to PDF)[2024-01-31]
您正在从流中读取两次但只写一个缓冲区。 改变这个: 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 ...