Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:22:15+00:00 2026-06-14T15:22:15+00:00

I am trying to do some calculations in my query and i think postgresql

  • 0

I am trying to do some calculations in my query and i think postgresql is handling the math differently than mysql is but i’m not sure where the difference is. This is my query from my controller:

Invoice.find(params[:id], :joins => :invoice_line_items, :select => "invoices.id, SUM(invoice_line_items.hours * invoice_line_items.rate) as subtotal, SUM(invoice_line_items.hours * invoice_line_items.rate) - (SUM(invoice_line_items.hours * invoice_line_items.rate) * (invoices.discount_percentage / 100)) as total", :group => "invoices.id")

In my development environment i am using mysql and in my production environment i am using postgresql. These are the outputs that i am getting. For reference, the discount_percentage is 20.

MySQL:

 |  id  |  subtotal  |  total         |
----------------------------------------
 |  21  |  570.0000  |  456.00000000  |

Postgresql:

 |  id  |  subtotal  |  total         |
----------------------------------------
 |  9   |  570.0000  |  570.00000000  |

It looks like it’s something to do with the percentage and total. Anyone have any ideas? By the way, the MySQL result is what i am wanting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:22:16+00:00Added an answer on June 14, 2026 at 3:22 pm

    Postgres is doing integer division.

    Select                    MySQL   Postgres
    -----------------------   -----   --------
    select 999 / 100 as a     9.99    9
    select 999 / 100.0 as a   9.99    9.99
    

    So, change the x / 100 to x / 100.0 to get them both to behave the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to perform some calculations with a form but every time i
I am trying to create a program that will do some simple calculations, but
I'm trying to do some calculations within a SELECT query, using user variables to
I'm trying to do some calculations involving ray tracing, but am a little confused.
I'm trying to perform some calculations on a non-directed, cyclic, weighted graph, and I'm
Hi I am trying to do some calculations for a unit converter im creating
I'm trying to post some information from a from do so some calculations, however
I'm trying to make some time calculations in where statement. I would like to
I'm trying to generate a data set, and I think recursion is required, but
I have 2 tables that I'm trying to use to perform some calculations. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.