Closed bczifra closed 5 years ago
Here is a solution:
package main
import (
"fmt"
"github.com/thedevsaddam/gojsonq"
)
const data = `{
"products": [
{
"name": "foo",
"price": 10
},
{
"name": "foo",
"price": 20
},
{
"name": "bar",
"price": 5
}
]
}
`
func main() {
jq := gojsonq.New().JSONString(data)
avg := jq.From("products").GroupBy("name").More().From("foo").Avg("price")
fmt.Printf("Avg: %.3f\n", avg)
}
@bczifra Hope this will help you. Closing the issue.
Given the following data:
how would I try to query for the average price per distinct name? I've tried
.From("products").GroupBy("name").Select("price").Avg();
and.From("products").GroupBy("name").Avg("price")
but those both result inNaN
.