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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:34:50+00:00 2026-05-25T09:34:50+00:00

I would like to thank in advance for any help. My problem relates to

  • 0

I would like to thank in advance for any help.

My problem relates to two tables in MySQL (Now switching to postgresql). The tables are related to a ticketing database.

a) booking. It has four columns       ccode,date,time,amount
b) account  It has three columns      ccode,date,amount

The booking table has ticket bookings and account table has advances and payments received.

I have to prepare a statement of account based on ccode (customer code).

The statement shows columns as below

*Ccode    Type    Date     time    amount    balance*

- the report in sorted on ccode and then on date (account table row appears first)
- Type column displays B or A depending on record type
- Time column is present only in booking table
- Report has a running balance for each row 
- At the end for a customercode, the totals of amount and balance is displayed

I have had success, so far in creating a join as below. (and after dicussion below, have been able to generate TYPE column using IF)

   
SELECT     booking.cname, booking.bdate, booking.btime, booking.rate, booking.ID,
           IF(booking.btime IS NOT NULL, "B", "A") AS type, account.cname, account.date,
           account.amount, account.ID 
FROM       booking 
LEFT JOIN  account ON booking.bdate = account.date AND booking.cname=account.cname AND 
           booking.rate = account.amount  
UNION 
SELECT     booking.cname, booking.bdate, booking.btime, booking.rate, booking.ID, 
           IF(booking.btime IS NOT NULL, "B", "A") AS type, account.cname, account.date,
           account.amount, account.ID  
FROM       booking 
RIGHT JOIN account ON booking.bdate = account.date AND booking.cname=account.cname AND 
           booking.rate = account.amount

It displays all the records. A report can be generated using this table.

But is there a way to display the formatted report just by SQL.

I can change the order of columns and even add or remove existing ones as long as Record type is known and a running balance is displayed against each record.

A SAMPLE REPORT —- REPORT A

CODE          DATE           TYPE              AMOUNT            BALANCE    TIME

A1           02/19/2011       A                 50               50        
A1           02/20/2011       B                 35               15          1230
A1           02/21/2011       A                 40               55
A1           02/21/2011       B                 20               35          1830


optional > TOTAL Account = 90    Booking = 55    Balance = 35 

A SAMPLE REPORT —- REPORT B

CODE          AMOUNT BOOKED             AMOUNT PAID           BALANCE

A1                      50               50                     0
A1                      35               15                     20
A1                      40               55                    -15
A1                      20               35                    -15

this is a weekly statement version of REPORT A. 
the reason is i can add where and between to get only records in a given week. 
and since it is a weekly report, running balance is just omitted. 
It is report grouped for all entries with customercode A1 present 
   in booking and account tables.

thanx
  • 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-25T09:34:51+00:00Added an answer on May 25, 2026 at 9:34 am

    I have found the answer.

    It is to use cummulative sql statement to find a running balance

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

Sidebar

Related Questions

First I would like to thank in you in advance for any help in
Thank you in advance for any help. I have a website which has OpenGraph
Ok I fixed the original problem but I would like now is to add
Right first of I would like to thank everyone for helping me out on
Once again my silliness has struck. I would like to thank everyone who helped
I hope you can help solving my problems. Any help is much appreciated. Thank
I'm having this problem with C++ classes. I would like to get pointer to
Thank you very much in advance for the help. I'm trying to byte-compile my
I would like to think of myself as a decent SQL Server programmer but
I would like to have more than one button. I tried to copy code

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.