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

  • Home
  • SEARCH
  • 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 6932091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:43+00:00 2026-05-27T11:39:43+00:00

Hopefully I can do this without writing a book… I’m working on a system

  • 0

Hopefully I can do this without writing a book… I’m working on a system for a Surveying company. They’re also throwing in an accounting section, and one of the functionalities it needs is to find jobs that are not completely paid off.

A few points to be made:

  • A ‘job’ is a project, essentially. There are different types of surveys.
  • A job can have more than one “type” of survey in it, thus having more than one price that is calculated into the job’s total price.
  • Payments are made on individual jobs (the client might send 30 checks if they have 30 jobs, it’s an accounting thing)
  • Job types are dynamic (they can create/delete them from the system panel) – so I can’t hardcode these things

Here’s the applicable database structure:

table jobs: job_id, client_id
table job_types: type_id, type_name
table job_type_assoc: id_job, type_id, price
table payments: payment_id, job_id, amount

Note: payments aren’t made on each job type, but the JOB as a whole (again, as opposed to the client’s account having a “balance”).

I need to somehow pull jobs where the total of price from job_type_assoc is less than the total of amount in payments.

I don’t know if this is possible in mysql alone or if php would be more efficient – also, their old system has about 340,000 jobs in it. Granted that they won’t have the accounting info from then, they do have a lot of work and the new entries will build quickly, AND if I somehow do it in PHP where I end up querying the jobs table a lot, it might get messy.

  • 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-27T11:39:44+00:00Added an answer on May 27, 2026 at 11:39 am

    One possible way you can do this is with a clever combination of subqueries.

    select * from 
      (select job_id,
        (select ifnull(sum(job_type_assoc.price),0) from job_type_assoc
           where jobs.job_id = job_type_assoc.id_job) as amount_due,
        (select ifnull(sum(payments.amount),0) from payments
           where jobs.job_id = payments.job_id) as payments
        from jobs) as outstanding
      where payments< amount_due;
    

    This shouldn’t be too bad a query to run, if you have properly indexed job_type_assoc and payments.

    Please note that I haven’t tested this exact query, so it might need tweaking. I’ve run the same query against tables on my local DB.

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

Sidebar

Related Questions

Hopefully I can ask this without being confusing. I am a photographer and I
Hopefully, this fictitious example will illustrate my problem: Suppose you are writing a system
Hopefully I can explain this without overcomplicating the issue, so please bear with me.
Sorry for the unhelpful title, but hopefully I can explain this well enough. Lets
This is a weird one, but hopefully someone can give me an idea here.
Ok, this is bit of an obscure question, but hopefully someone can help me
Hopefully this is a simple one, but can anyone provide some simple c# code
This is hopefully very easy to do, but I can't find any doco on
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
Hopefully you can help me with this. An assembly is already in the GAC.

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.