你不用次次都從頭走到尾巴
不是SQL專家的回答
Even you always need process from the head to the tail, you can pre-generate some aggregate tables to improve the performance.
Depending on how accurate you want, the aggregate tables can be generate at night and of course you need use aggregate awareness SQLs.