This question is related to a previous question that I asked: Using JSON in d3v4 stacked bar chart.
Background: For the stacked bar chart, I am trying to represent a series of hospitals that show the total count of categories (for each hospital) that each patient's diagnosis belongs to. I produced my JSON file by using a SQL query and exported it.
Question: How can I change my JSON array data structure to combine multiple categories of the same hospital?
My JSON array data structure (a small portion) for the stacked bar chart looks like this:
[{
"hospitalName": "hospital1",
"category": "Injury & Poisoning",
"Females": "0",
"Males": "4",
"Unknown": "0",
"count": "4"
},
{
"hospitalName": "hospital1",
"category": "Symptoms, Signs, & Ill-Defined Conditions",
"Females": "1",
"Males": "1",
"Unknown": "0",
"count": "2"
},
{
"hospitalName": "hospital2",
"category": "Mental Disorders",
"Females": "0",
"Males": "1",
"Unknown": "0",
"count": "1"
}]
The desired JSON array data structure:
[{
"hospitalName": "hospital1",
"Injury & Poisoning": "4",
"Symptoms, Signs, & Ill-Defined Conditions": "2"
"Females": "1", <--- the count of females is increased
"Males": "5", <--- the count of males is increased
"Unknown": "0",
"count": "6"
},
{
"hospitalName": "hospital2",
"category": "Mental Disorders",
"Females": "0",
"Males": "1",
"Unknown": "0",
"count": "1"
}]
Is this possible to produce using a SQL query or could I use PLSQL instead?