When I did a startKey of [0,0,0,“2012-01-01”] based on the document values you provided above. This resulted in the ability to group by 1,2,3 or 4 for the full value:
group level 3:
[301,368,1]
group level 4:
[301,368,1,“2012-04-01”]
I suggest modifying the start key a bit and seeing if you get a better result?
Don’t forget to add a reduction as well and save the view. I used the built-in _count reduction.
You have 4 values returned, with the date being the last returned value. In order to group them by level 3, the date would have to be the 3rd value, but then you would have to choose what would not not return for the 4th level or what would you simply not include. Having said that, you could construct your view so that 2 of the values are combined as a string but separated by a “,” so as to be able to group at 3 levels and still see 4 values at the application.
Beware though that one pair would be concatenated as a string if you chose to do this.
function (doc, meta) {
emit([[parseInt(doc.loc_no), parseInt(doc.host_no)], parseInt(doc.pool_id), doc.race_date], parseFloat(doc.netsales));
}
I tried to convert below query and I need my view results as result of query. Have a look and give me your suggestions.
select loc_no, host_no, pool_id, count(*), SUM(netsales) from summary where race_date < ‘2012-01-31’ and race_date > ‘2012-01-01’ and loc_no = 319 group by loc_no, host_no, pool_id order by host_no;