Surpassing MySQL’s TIME value limit of 838:59:59

Have a look at timestampdiff which doesn’t have the TIME limitation. I.e. something like (untested): SELECT CONCAT( TIMESTAMPDIFF(HOURS, entry_end_time, entry_start_time), “:”, MOD(TIMESTAMPDIFF(MINUTES, entry_end_time, entry_start_time),60) ) AS total FROM entry WHERE entry_date BETWEEN ‘2012-01-01’ AND ‘2012-12-31′ AND user_id = 3 The concats not ideal, I’m sure there will be a more elegant solution.

Sum in nested document MongoDB

As Sammaye indicated, you need to $unwind the Egresos array to duplicate the matched doc per array element so you can $sum over each element: db.Cuentas.aggregate([ {$match: {“Usuario”: “MarioCares”} }, {$unwind: ‘$Egresos’}, {$group: { _id: null, “suma”: {$sum: “$Egresos.Monto” } }} ])

Sum of the integers from 1 to n

There is no need for a loop at all. You can use the triangular number formula: n = int(input()) print(n * (n + 1) // 2) A note about the division (//) (in Python 3): As you might know, there are two types of division operators in Python. In short, / will give a float … Read more