I have been working on a GraphQL and firing queries to get the JSON response into react app.
But I need to fire a query which will return me the max and min value from the column.
I have gone through the document of GraphQL but nowhere I found the way to accomplish this.
{
schneider(where: {_and: [{device_time: {_gte: "2018-09-04T20:11:42.097+05:30"}}, {device_time: {_lte: "2018-09-04T20:12:43.187+05:30"}}]}) {
active_energy_received
}
}
The above query gives me the list of values that are between the two provided dates.
{
"data": {
"schneider": [
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0.82099998
},
{
"active_energy_received": 4.3699998856
},
{
"active_energy_received": 0
},
{
"active_energy_received": 0.820999979972839
},
{
"active_energy_received": 4.3699998856
}
]
}
}
Now, instead of all the values, I want only max and min value from this list.
UPDATE:
I am using hasura.io with postgreSQL.
If you are using Hasura.io then you can use the customized API queries to ORDER BY and LIMIT for the MIN and MAX result.
Example for MAX value:
query {
table_name(limit: 1, order_by: {time: desc}) {
data
time
}
}
Example for MIN value:
query {
table_name(limit: 1, order_by: {time: asc}) {
data
time
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With