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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:05:11+00:00 2026-05-30T19:05:11+00:00

I have budgets similar to example below, where: some budgets are person specific, some

  • 0

I have budgets similar to example below, where:

  • some budgets are person specific,
  • some are for the entire team, and
  • a mixture where some are part allocated to a specific person while the rest is for the rest of the team.

I can link Budgets to Summary_of_spend, but what I need to do is always link on year and budget type, but only on the person if one exists in the budget. Where there is no person in the budget, just default to sum together the amounts for that group.

How would I create a join that does for that?

(Sorry, not come across anything like this before and not sure what it’s call, let alone how to solve it. I’m using SQLite by the way.)

Budgets
YEAR, TYPE, PERSON, AMOUNT
2010, Sales, Bob, 1000
2010, Sales, John, 1000
2010, Sales, Fred, 1000
2010, Marketing, Null, 5000
2010, Special, Null, 3000
2010, Special, Bob, 1000
2011, Sales_budget, Bob, 1100
2011, Sales_budget, John, 1100
2011, Sales_budget, Fred, 1100
2011, Marketing, Null, 6000
2010, Special, Null, 3000
2010, Special, Bob, 1000

Spend
DATE, BUDGET, PERSON, AMOUNT
01/01/2010, Sales, Bob, 50
02/01/2010, Marketing, Bob, 100
...

Summary_of_spend
YEAR, BUDGET, PERSON, AMOUNT
2010, Sales, Bob, 950
2010, Sales, John, 888
2010, Marketing, Bob, 500
2010, Marketing, John, 500
2010, Marketing, Fred, 500
2010, Special, Bob, 333
2010, Special, John, 222
2010, Special, Fred, 222
...

Budget_and_summary_of_spend
YEAR, BUDGET_TYPE, PERSON, BUDGET_AMOUNT, SPEND_AMOUNT
2010, Sales, Bob, 1000, 950
2010, Sales, John, 1000, 888
2010, Sales, Fred, 1000, 0
2010, Marketing, Null, 5000, 1500
2010, Special, Null, 3000, 444
2010, Special, Bob, 1000, 333
...
  • 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-30T19:05:12+00:00Added an answer on May 30, 2026 at 7:05 pm

    You might want to try this:

    from budget inner join summary_of_spend
     on budget.Year = summary_of_spend.Year
       and budget.type = summary_of_spend.Budget
       and ifnull(budget.person, 'ItsDepartment') = ifnull(summary_of_spend.Person, 'ItsDepartment')
    

    You can join tables based on any expression. In this case I joined them in such a way that if person is not null the other side must have record for this person and if it is null I substitute some string that will not be found among persons. This is of course weak spot, and if it bothers you you can change join to a combination of and’s and or’s.

    If you need records from budget where no money has been spent, change “inner join” to “left join”.

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

Sidebar

Related Questions

I would like to use Markov models for some architecture simulations, but don't have
Whereever I have looked, the functional specifcations are some sort of documents with the
I have two tables: Budgets and Consultants. There is a 1 to 0..1 relation
Let's say i have a budget of $40 and i want to spend specific
I have the following text input on a budget calculator form which displays the
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

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.