Need MySQL query: translate AWK script to MySQL query...

jerry_gilels
jerry_gilels used Ask the Experts™
on
Need a MySQL query that will produce the total so far today of telephone minutes used.  Have been running awk script against flat file for years.  Moved to MySQL, now need equivalent query.  See the awk code below.

Would like a select statement that will round each record's seconds as the awk script provides for below.
-----------  AWK SCRIPT -------------
 
global roundrate = 6        // six-second increments
global minimum = 12        // minimum number of seconds
 
{
        total_minutes += (round($0,roundrate,minimum)/60)
}
 
 
function round(amount,roundrate,minimum)
{
   tstamt = amount * 1
   if (tstamt > 0)
   {
      if (tstamt < minimum)
         tempn = minimum
      else
         tempn = int((tstamt + roundrate - 1) / roundrate) * roundrate
   }
   else   
      tempn = tstamt
 
   return tempn
}
 
END {
 
        print total_minutes
}
---------------- END -----------------

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
I think you need these 2:
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html
http://dev.mysql.com/doc/refman/5.0/en/case-statement.html

case when amount <= 0 then amount when amount < 12 then 12 else round( amount + 6 - 1) / 6 ,0) * 6 end as result

Open in new window

Author

Commented:
I still had to figure out the select statement.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial