I have a program that "selects * from table" and the processes this data, like this:
1) Group each entry by their datetime column, ignoring second precision, order the group by an index value (column i)
2) Find the largest, smallest, first, and last value of column x, in each group.
3) Sum all the values of column y in each group
4) Loop over all data, the write to disc.
I have already written the program, so the task is done, but I think the whole think looks like it could be done easily directly in sql. If this can be done in a "short enough" query, then I'd have fewer bugs to worry about in my own code.
Mainly as an exercise to myself in sql, I'm wondering just how easily this can be done in sql.
Selecting the max(x) and min(x) values of each group is probably quite simple, and I'm hoping the first/last problem could be solved by using max(i)/min(i), but I'm not very familiar with sql, and just randomly guessing seems like a big waste of time.
Again, my question is really "how short" this can be, since if the query requires a lot lines, I'm actually worse of, since I would then need to debug in an unfamiliar language.