Nope, I'll elaborate the result after the select. I need directly the SUM for each hour from output SQL select!
Maybe using grouping (and SUM) by partial, but I don't know how to implement yet!
---------- Post updated at 11:48 AM ---------- Previous update was at 11:40 AM ----------
Well, I found myself a solution, it was so simple!!!
SELECT data, SUM(`tot`) as SUM, COUNT(tot) As HOUR FROM `data` GROUP BY MID(data, 8,2)
Not sure if this is strictly a unix issue, but in any case,......
What database are you using? There is likely a date/time function we can call in your query to produce your results straight off the bat.
Your logic of using a where clause based on being like '%/00', thrn '%/01' etc. could generate you spurious values.
Something like:
SELECT to_char(to_date(data,'yymmdd/hhmi'),'yymmdd/hh') timestamp , SUM(tot) sumtot
FROM table
GROUP BY timestamp
ORDER BY timestamp ;
Might get you started and perhaps use of a trimming function to ignore the minutes value will get the actul result you want straight from the SQL query, but like I say, it depends on the database server you are using.
Wholly untested bit of theory, but I hope that this helps a bit. If you respond with the database software, you may get a complete response. In my opinion you would save processing time to get the database to perform the work within the initial query rather than get the data to a file then post-process it to create the output you want. You can use the to_char function of many databases to give you date/time output in the format you want too.
Thanks both! I'll analyze your select since my one have some problem when day change (the first 6 chars)!
...and yes, I'm using MySQL and bash script, but as rbatt1 said, I would save processing time to get the database to perform all the work! Database is not on the same machine, so I save also CPU usage!