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

The Archive Base Latest Questions

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

I have a table where I keep information about financial returns. The columns includes

  • 0

I have a table where I keep information about financial returns. The columns includes receipts, repairs, service_amount, tyres, fuel, salaries_allowances, others.

I would like to get the cumulative net return like:

Date        Receipts       repairs      service amount  Total costs  net Return
2012-01-10  0.00           120,000.00   0.00            120,000.00   120,000.00
2012-01-12  60,000.00      0.00         0.00            60,000.00    60,000.00

I am currently using this query:

SELECT 
        a.consignment_date, a.receipts, a.service_amount, a.repairs, a.tyres, 
        a.salaries_allowances, a.clearing_fee, a.others, 
        a.service_amount + a.repairs + a.tyres + a.salaries_allowances + a.clearing_fee + a.others as total_costs,
        (b.receipts -(a.service_amount + a.repairs + a.tyres + a.salaries_allowances + a.clearing_fee + a.others)) as netreturn 
FROM 
      vw_local_freight a CROSS JOIN vw_local_freight b 
WHERE 
      a.consignment_date >= b.consignment_date AND a.vehicle_no='123X' 
GROUP BY a.consignment_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-05-30T11:31:01+00:00Added an answer on May 30, 2026 at 11:31 am

    I would look at a query like

    SELECT 
        consignment_date.*,
        consignment_date.credits - consignment_date.costs AS totalCosts,
        (@runningTotal := @runningTotal + consignment_date.credits - consignment_date.costs) AS netReturn
    FROM (
        SELECT
            consignment_date,
            SUM(receipts) AS credits
            SUM(service_amount + repairs + tyres + salaries_allowances + clearing_fee + others) AS costs
        FROM vw_local_freight 
        WHERE vehicle_no = '123x'
        GROUP BY consignment_date
    ) AS a, (SELECT @runningTotal := 0) AS b
    

    The subquery tallies up your costs and credits, then the outer query performs your running total. If you need individual column sums within the inner join then they can be added in easily enough.

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

Sidebar

Related Questions

I have a table of housing listings. I would like to keep a maximum
I have a couple of triggers on a table that I want to keep
I have table with 3 columns A B C. I want to select *
We have a database that contains information about time booked to projects. We have
First of all, let's define a few tables: Users table will store information about
Rookie question I know. I have a table with about 10 fields, one of
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have table with some fields that the value will be 1 0. This

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.