Re: Need Elegant SQL
Posted in 1993
Bharat, How about using one of my favorites, the group by statement: select (timestamp - extend ("0:0", hour to minute)) / 10 * 10, sum(xyz) from abcd group by 1 Subtracting the "0:0" time from the timestamp will turn your datetime into an interval expression and allow you to divide and multiply it by 10 to drop your last digit off of the minutes, leaving you to group by the 10 minute intervals. From here you could put this into a temp table, delete out of your current table, and then update your table values with the new ones in the temp table. (If you use a temp table, don't forget to give the columns - which are now expressions - names: eg. sum (xyz) sum_of_xyz .) +-------------------------------+----------------------------------------+ | Cathy Kipp | Internet: ckipp@vth1.vth.colostate.edu | | Veterinary Teaching Hospital | | | Colorado State University | Voice: (303) 491-1294 | | Fort Collins, CO 80523 | Fax: (303) 491-1205 | +-------------------------------+----------------------------------------+