There is much debate as to whether or not data calculations should be done in the web app or in the database. There are good arguments on both sides. Depending on what is being calculated, executing calculations in some web programming languages tends to be faster than doing the same thing in the database. However, keeping the calculation in SQL means that the functionality is portable, and often means that less data needs to be retrieved from the database.