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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:04:36+00:00 2026-06-01T19:04:36+00:00

For example, I have the following table: date | id | num 01-01 |

  • 0

For example, I have the following table:

date | id | num
01-01 | a | 10
01-02 | a | 14
01-02 | b | 2
01-03 | a | 19
01-03 | b | 5
01-04 | a | 13

I want to substract num of b from a, that is, the result will be:

01-01 | 10    //10
01-02 | 12    //14-2
01-03 | 14    //19-5
01-04 | 13    //13

I tried the following SQL query but if there is no record of b on a date, it will return \N.

SELECT tba.date, numall-numout
FROM (
    SELECT date, num AS numall
    FROM tb
    WHERE id = "a"
) tba
LEFT JOIN (
    SELECT date, num AS numout
    FROM tb
    WHERE id = "b"
) tbb
ON tba.date = tbb.date
  • 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-01T19:04:37+00:00Added an answer on June 1, 2026 at 7:04 pm

    If there’s no matching B, a left join will return a null, meaning you’re doing

    numall - NULL
    

    which results in a NULL. To get around this, you’d have to do

    numall - COALESCE(numout, 0)
    

    to force a 0 for the non-existent ‘b’ dates.

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

Sidebar

Related Questions

I have the following example in a SQL table Cust Group Sales A 1
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
Ok, I have an example table with the following information and query. First up
I have a table that has several date fields. For example, in the defects
I have the following tables: --table sportactivity-- sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time (tuple
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),
I have the following SQL Query: select Subjects.S_ID as ID, Subjects.S_ParentID as ParentID, Subjects.S_Name
I have the following table: Transaction_ID int(9) NO PRI NULL auto_increment Datetime date NO
I have a strange problem. I convert a date using the following CONVERT(varchar(64), table.[Date],
I have the following MySQL. SELECT `outputtable`.`date`, count(*) as `count` FROM ( SELECT CONCAT(DATE(`mytable`.`starttime`),'

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.