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 7652057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:40:00+00:00 2026-05-31T11:40:00+00:00

I have the following tables (simplified): hours hour_rates – user_id – user_id – date

  • 0

I have the following tables (simplified):

   hours               hour_rates
 - user_id            - user_id
 - date               - date
 - hours              - hourly_rate

Hours table example:

1 - 2012-03-19 - 8

This means that user with id=1, at 2012-03-19 worked 8 hours in total.

The hourly rate for a person can change in time, so I have the second table:

hour_rates table Example

1 - 2011-12-01 - 20
1 - 2011-12-20 - 25

So for user with id=1, we set a hourly rate of 20$ at 2011-12-01.
We changed his hourly rate at 2011-12-20, to 25$.

What I want is, to calculate how much I have to pay for a given user (ex. id=1) for a given period (ex. 2012-01-01 -> 2012-02-01).

Can I calculate this simply mysql side?
If not, how to do it in an efficient way?

  • 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-05-31T11:40:01+00:00Added an answer on May 31, 2026 at 11:40 am

    In hour_rates table you should have two dates: start_date and end_date this means from start_date to end_date the emplyer has been paid x$ per hour.

    Then use the same query proposed by bpgergo modified like this:

       select sum(h.hours * hr.hourly_rate) as pay
       from hours h, hour_rates hr
       where h.user_id = :user_id --here you will set the user id parameter
       and h.user_id = hr.user_id and (h.date BETWEEN hr.start_date AND hr.end_date 
       and h.date between STR_TO_DATE('01,1,2012','%d,%m,%Y') and STR_TO_DATE('01,1,2011','%d,%m,%Y')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table (simplified): user_id date hours 1 2012-03-01 5 2 2012-03-01
I have the following two tables (simplified for this question): CREATE TABLE team (
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have the following 4 tables (simplified for this question): Company CompanyId | Name
Let's suppose I have a the following simplified example database consisting of three tables:
Using this as a simplified example, assume I have a table that has some
I have the following (simplified for example) tables in my system: View the E-R
I have the following two (simplified for the sake of example) tables in my
I have the following (simplified) database tables: Products - ProductID, int, PK - Name,
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User

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.