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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:45:10+00:00 2026-06-16T02:45:10+00:00

I have 3 tables as described below MonthlyOrder table 4 columns CustomerID DateID (represented

  • 0

I have 3 tables as described below

MonthlyOrder table 4 columns
CustomerID
DateID (represented in integer and as the first of the month = 20121201)
OrderCount – INT

HoursSpend Tbale has 4 columns
CustomerID
DateID
Function – VARCHAR() — Functions are Reporting, Admini and Sales calls
Hours – INTEGER — Hours spent on each function during the month

Rates Table has 3 columns
CustomerID
AccountRate — Money (IF NULL then default is $50)
OperationRates – Money

The calculation that I need to achieve from this tables are
(LoadCount*AccountRate) + ((Hours for Reporting Function from HoursSpend table + Hours for Amin + Hours for Sales calls) * OperationRates from Rates table)

Please advise on the best way to achieve this calculation
MonthlyOrder
CustomerID DateID OrderCount
1 20121201 20
1 20121202 10
2 20121210 100
HoursSpend
CustomerID DateID Function Hours
1 20121201 Reporting 2
1 20121201 Admin 3
1 20121201 Sales Calls 5
1 20121201 Training 10
Rates
CustomerID AccountRate OperationRates
1 $18 $50

CALCULATION – > (OrderCount*AccountRate) + ((Reporting Hours + Admin Hours + Sales Calls Hours) * OperationRates)
EXAMPLE for customerID 1 on 20121201 -> (20*18) + ((2+3+5) * 50) = $860
** Notice that the Hours for Training are not included as the only hours that I care about is Reporting + Admin + Sales Calls

  • 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-16T02:45:12+00:00Added an answer on June 16, 2026 at 2:45 am

    Assuming that following column combinations are unique: MonthlyOrder[CustomerID,DateID], HoursSpend[CustomerID,DateID,Function], Rates[CustomerID]
    you could use something like:

    select mo.CustomerID, mo.DateID, mo.OrderCount*max(AccountRate) +
            (sum(rep.hours)+sum(adm.hours)+sum(sc.hours))*max(rt.OperationRates)
    from MonthlyOrder as mo
      join Rates as rt                on rt.CustomerID = mo.CustomerID
      left join HoursSpend as rep     on rep.CustomerID = mo.CustomerID and
                                         rep.DateId = mo.DateId and
                                         rep.Function = 'Reporting'
      left join HoursSpend as adm     on adm.CustomerID = mo.CustomerID and
                                         adm.DateId = mo.DateId and
                                         adm.Function = 'Admin'
      left join HoursSpend as sc      on sc.CustomerID = mo.CustomerID and
                                         sc.DateId = mo.DateId and
                                         sc.Function = 'Sales Calls'
    group by mo.CustomerID, mo.DateID, mo.OrderCount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have 4 tables as described below: Table 1: Element element_id [integer] (PK)
I have two tables described below. What I need is a single query that
I have two tables, REPORTS and REPORT_TYPE which are as described below. REPORTS REPORT_TYPE_ID
I have 3 tables as described below , table1 'ads' id userid 1 47
I have data in a mysql table in long / tall format (described below)
I have two view controllers which should work like described below: First view controller
I have a polygon structure in an sql2005 db as described below. CREATE TABLE
I'm seeing basically the same issue described here I have a table that starts
I have the same problem as described in ( Last record of Join table
I have 3 tables listed below: Blog BlogArticle Article ---- ----------- ------- id id------blog_id

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.