0
Welcome Guest! Login
0 items Join Now

MySQL query, erm....query

    • ladbroke's Avatar
    • ladbroke
    • Sr. Rocketeer
    • Posts: 166
    • Thanks: 4

    MySQL query, erm....query

    Posted 4 years 11 months ago
    • Hiya, I am trying to return some results from a mysql database (it's Magento, but that's not really important). I am trying to add up all the values in one column to get a grand total. I will save this query as a view, and then use the view in a project I am working on.

      The query I am using is this:

      SELECT sum(base_total_invoiced) as base_total_invoicedSum, state
      FROM my_table_name
      WHERE state="complete"

      This returns the correct value, but it is to 4 decimal places. I would like to return this value only to 2 decimal places. It's a monetary value so looks a bit odd as 37567.0000

      Any help much apreciated!
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 85144
    • Thanks: 10920
    • Web Designer/Developer

    Re: MySQL query, erm....query

    Posted 4 years 11 months ago
    • ladbroke's Avatar
    • ladbroke
    • Sr. Rocketeer
    • Posts: 166
    • Thanks: 4

    Re: MySQL query, erm....query

    Posted 4 years 11 months ago
    • Hi, I had seen that link on Stackoverflow when I was searching for solutions, but I can't tell from that if it's good practise to use TRUNCATE or not? Also I'm not sure where in my query I should place it.
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 85144
    • Thanks: 10920
    • Web Designer/Developer

    Re: MySQL query, erm....query

    Posted 4 years 11 months ago
    • Did you follow the link therein? http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_truncate

      what do you want trucated value or rounded value? either way it's all there in the mysql docs.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.

Time to create page: 0.089 seconds