Possibly what you are looking for is "GROUP BY aDate", which would return one row for each distinct aDate and do the computation within each group of records. Also, try "sum(column)/2 as c" if you want half of the groups' sum; the value of v is only known at the end of the group and would be hard to determine during processing of rows.