Link to home
Start Free TrialLog in
Avatar of jerry_gilels
jerry_gilelsFlag for United States of America

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jerry_gilels

ASKER

I still had to figure out the select statement.