I noticed something. I was testing the SQL and I might have put in the wrong value.
At the end of the SQL in my examples above I have "not like" and should be just "like"
exten => _.,n,MYSQL(Query resultid ${connid} SELECT if(sum(duration) < 60000, 1, 0) FROM cdr WHERE DATE(calldate) >= DATE(NOW()) - INTERVAL 30 DAY and dstchannel like '%trunkname%')
vs this one
exten => _.,n,MYSQL(Query resultid ${connid} SELECT if(sum(duration) < 60000, 1, 0) FROM cdr WHERE DATE(calldate) >= DATE(NOW()) - INTERVAL 30 DAY and dstchannel not like '%trunkname%')
Also, the above SQL statement goes from "now" (whatever point in time the script is executed" and goes back 30 days. This select statement does the same thing, except it goes back to the first of the current month ('%Y-%m-01 ). Useful if your time restrictions reset on the start of the month.
SELECT if(sum(duration) < 60000, 1, 0) from cdr where (calldate between DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() ) and dstchannel not like '%TRUNKNAME%'