简体   繁体   English

SQL / PHP获取过去30天的每日记录

[英]SQL/PHP get daily records for the past 30 days

hello i am trying to use line chart ( https://developers.google.com/chart/interactive/docs/gallery/linechart ) from google chart and i don't know the query to get how many patients went into the hospital each day for the past 30 days so that i can add it to the data.addrow on the linechart Here is what my table looks like: 你好,我正在尝试使用Google图表中的折线图( https://developers.google.com/chart/interactive/docs/gallery/linechart ),但我不知道要查询多少病人才能进入医院过去30天的日期,这样我就可以将其添加到linechart上的data.addrow中。这是我的表格的样子:

pPatient

pName                 pDate
Sample Name           2017-08-15
Another Name          2017-08-15
Another Name Again    2017-08-15
Name Here             2017-08-14
Name Again            2017-08-13

i need a sql query so that i can dynamically change the line chart 我需要一个SQL查询,以便可以动态更改折线图

google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawBasic);

function drawBasic() {

      var data = new google.visualization.DataTable();
      data.addColumn('number', 'Day');
      data.addColumn('number', 'Patients');

      data.addRows([
       "the part where im having a problem"

      var options = {
        hAxis: {
          title: 'Day'
        },
        vAxis: {
          title: 'Number of Patients'
        }
      };

      var chart = new google.visualization.LineChart(document.getElementById('chart_div'));

      chart.draw(data, options);
    }

i got the code from the google docs and i just edited it a little to fit my situation 我从Google文档中获取了代码,并对其进行了一些修改以适合我的情况

from what i can gather, all you need is the query, right? 从我可以收集的信息中,您所需要的只是查询,对不对? i'm assuming you have a method to send the query and receive the data. 我假设您有一种发送查询和接收数据的方法。

in that case, the best and easiest solution would be a simple COUNT query w/ some grouping. 在这种情况下,最好和最简单的解决方案是使用一些分组的简单COUNT查询。

SELECT COUNT(pName)
FROM pPatient
WHERE DATE(pDate) > CURDATE() - 30

if you want them to be sorted by the month, day, and year, you can add this to the end. 如果希望按月,日和年对它们进行排序,则可以将其添加到末尾。 it'll list them by matching dates, using pDate as the argument to match them by: 它将通过匹配日期列出它们,并使用pDate作为参数来匹配它们:

GROUP BY DATE(pDate)

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

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