I have two buckets in couchbase server:
demographics {“country_id”:“BGD”,“country_name”:“Bangladesh”,“population”:“164700000”,“area”:“148460”,“density”:“1265”},
{“country_id”:“DEU”,“country_name”:“Germany”,“population”:“83200000”,“area”:“357386”,“density”:“232”},
statistics:
{"country_id":"DEU","dt":"2022-02-17","confirmed_cases":"235626","deaths":"261"},
{"country_id":"DEU","dt":"2022-02-16","confirmed_cases":"219972","deaths":"455"},
{"country_id":"BGD","dt":"2022-02-17","confirmed_cases":"3539","deaths":"20"},
{"country_id":"BGD","dt":"2022-02-16","confirmed_cases":"3929","deaths":"15"},
I want to retrieve the maximum deaths value countrywise. when i am trying to get max value using max() function, it’s not returning the maximum value and also query is giving error:
{
"code": 4210,
"msg": "Expression (`s`.`dt`) must depend only on group keys or aggregates."
}
Here is my query:
SELECT
d.country_name demographics, s.dt `statistics`, MAX([s.deaths,s])[1]
FROM
Demographics d
JOIN statistics s
On d.country_id=s.country_id
GROUP BY country_name
ORDER BY MAX(s.deaths) DESC;
I want the result like this: highest death with country
country_name dt deaths
GERMANY 2022-02-16 455
BANGLADESH 2022-02-17 20