score:2
I would do this way:
For every doctor do a query like this:
/* get all pregrant women for a doctor, group by month and count records */
SELECT MONTH( p.reg_date ), COUNT(*)
FROM nurse_dets n
INNER JOIN preg_reg_other p
ON n.nurse_id = p.nurse_id
WHERE n.doctor_id = 1301
AND n.reg_date IS NOT NULL
GROUP BY MONTH( p.reg_date )
ORDER BY p.reg_date ASC
This will give you, for every month, the count of pregnant women associated with the doctor with id 1301
Now, you could do a query like this for every doctor and, in every iteration, build a different serie for you chart
In the end you will pass all your series array to your client and fetch the data for highcharts
EDIT
Getting the value of 0 for the months where there are no pregnant women is a litte more complicated, as the group by doesn't return any value if there isn't at least one record to count. Try this way:
SELECT months.num, COUNT( p.preg_id )
FROM
( SELECT 1 AS num
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
UNION ALL SELECT 8
UNION ALL SELECT 9
UNION ALL SELECT 10
UNION ALL SELECT 11
UNION ALL SELECT 12 ) months
LEFT JOIN preg_reg_other p
ON months.num = MONTH ( p.reg_date )
INNER JOIN nurse_dets n
ON n.nurse_id = p.nurse_id
WHERE n.doctor_id = 1301
GROUP BY MONTH( months.num )
ORDER BY months.num ASC
First we manually build a table with the 12 months and "left join" with the other tables, so if there isn't any record, the final count should result in 0
I'haven't tested the query, but i hope you get the idea
Source: stackoverflow.com
Related Query
- Formatting JSON data monthwise for HighCharts using MySQL
- Formatting JSON Data with ColdFusion for HighCharts
- Formatting JSON from a Pandas data frame for Highcharts within a Django template
- JSON Data formatting for Highcharts
- Highcharts display label for pie chart using html table as data source
- HTML table as data source for highstock charts using highcharts
- Highcharts to populate data for pie chart using json object
- Highcharts using JSON - graph not displaying mysql data
- Using a flask variable as data source for highcharts
- Formatting PHP/MySQL data in correct JSON format for HighCharts
- Highcharts JSON formatting - splitting up and preprocessing data for charts?
- Load mysql data to Highcharts line chart using JSON
- how to create proper json data format from mysql for highcharts
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- Parsing JSON data for Highcharts
- How to format my json data for stack column chart in HighCharts
- Passing in Id for each data item in bar chart using highcharts
- How to create data in Json format for highcharts
- Retrieving JSON data for Highcharts with multiple series?
- JSON data not showing in highstock Candlestick chart using PHP & MYSQL
- Extracting data from a JSON call to a Postgres table for use in Highcharts (without PHP)
- Using Highcharts with mysql for Page Visits
- passing formatting JavaScript code to HighCharts with JSON
- Formatting data array correctly for Highcharts
- highcharts example for using data from database with mvc
- Formatting data points and Y-axis labels using HighCharts
- Two way data binding in Angular JS for graphs implemented using HighCharts
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- JSON Result for Highcharts Data Object in C#
- Gson to get Json value for a pie chart using Highcharts
More Query from same tag
- How to change color of donut chart in highchart?
- How to change the series plot display inside the scrollbar of the RangeSelector in highcharts.js
- How to remove the halo/glow around a marker upon hovering a series in Highcharts
- Highcharts minimum value for area charts y-axis
- How to format column chart data labels
- How do I auto scale an axis with a max height in highcharts?
- highcharts how to make x and y axis starting on the same zero using categories on yAxis
- call hidden value to highchart
- How to drilldown to third level when its data is determined by second's click event?
- Simple, Open source PHP wrapper for Highcharts library
- 3 layer donut chart in Highcharts
- R Highcharter - Countries displayed incorrectly on hcmap
- Formatting JSON Data with ColdFusion for HighCharts
- How do I change the style of the inner part enclosed by the lines(polar) chart created with highcharts?
- Highcharts - linear chart hidden in combination of graphs
- How to redraw SVG Rendered Text from Highcharts
- Html not rendering chart
- HighCharts Pattern Fill striped
- Avoid tooltips when printing a chart
- Adding Rails data to Highcharts series
- Highmaps support for zip5
- Does Highcharts use Cookies?
- How can I unescape and remove quot; from data served by rails into javascript
- Highcharts not working after jquery upgrade
- Combine 2 series in one Chart (not stacked)
- HighCharts / Highstock How to build 100% stacked area chart
- Highcharts combination chart from JSON data
- Formating my json for highcharts
- change color of highcharts legend page navigation buttons
- Applying custom style on ticks of Highchart