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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:36:44+00:00 2026-06-04T14:36:44+00:00

I am working on 2 problems for homework and after many hours I have

  • 0

I am working on 2 problems for homework and after many hours I have just about solved them both, the last issue I have is that both of my queries are coming back with doubled numerical values instead of single.

Here is what I have:

SELECT SUM(P.AMT_PAID) AS TOTAL_PAID, C.CITATION_ID, C.DATE_ISSUED, SUM(V.FINE_CHARGED) AS TOTAL_CHARGED
FROM PAYMENT P, CITATION C, VIOLATION_CITATION V
WHERE V.CITATION_ID = C.CITATION_ID
AND C.CITATION_ID = P.CITATION_ID
GROUP BY C.CITATION_ID;

and my other one:

SELECT C.CITATION_ID, C.DATE_ISSUED, SUM(V.FINE_CHARGED) AS TOTAL_CHARGED, SUM(P.AMT_PAID) AS TOTAL_PAID, SUM(V.FINE_CHARGED) - SUM(P.AMT_PAID) AS TOTAL_OWED
FROM (CITATION C)
LEFT JOIN VIOLATION_CITATION V
ON V.CITATION_ID = C.CITATION_ID
LEFT JOIN PAYMENT P
ON P.CITATION_ID = C.CITATION_ID
GROUP BY C.CITATION_ID
ORDER BY TOTAL_OWED DESC;

I am sure there is just something that I am overlooking. If someone else could kindly tell me where I went awry it would be a great help.

  • 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-04T14:36:46+00:00Added an answer on June 4, 2026 at 2:36 pm
    Select Sum(P.Amt_Paid) As Total_Paid, C.Citation_Id
        , C.Date_Issued, Sum(V.Fine_Charged) As Total_Charged
    From Payment P
        Join Citation C
            On C.Citation_Id = P.Citation_Id
        Join Violation_Citation V
            On V.Citation_Id = C.Citation_Id
    Group By C.Citation_Id
    

    First, you should use the JOIN syntax instead of using the comma-delimited list of tables. It makes it easier to read, more standardized and will help prevent problems by overlooking a filtering clause.

    Second, the most likely reason for having a sum that is too large is due to the join to the VIOLATION_CITATION table. If you remove the Group By and columns with aggregate functions, you will likely see that P.AMT_PAID is repeated for each instance of VIOLATION_CITATION. Perhaps, the following will solve the problem:

    Select Coalesce(PaidByCitation.TotalAmtPaid,0) As Total_Paid
        , C.Citation_Id, C.Date_Issued
        , Coalesce(ViolationByCitation.TotalCharged,0) As Total_Charged
        , Coalesce(ViolationByCitation.TotalCharged,0)
            - Coalesce(PaidByCitation.TotalAmtPaid,0) As Total_Owed
    From Citation As C
        Left Join   (
                    Select P.Citation_Id, Sum( P.Amt_Paid ) As TotalAmtPaid
                    From Payment As P
                    Group By P.Citation_Id
                    ) As PaidByCitation
            On PaidByCitation.Citation_Id = C.Citation_Id
        Left Join   (
                    Select V.Citation_Id, Sum( V.Find_Charged ) As TotalCharged
                    From Violation_Citation As V
                    Group By V.Citation_Id
                    ) As ViolationByCitation
            On ViolationByCitation.Citation_Id = C.Citation_Id
    

    The use of Coalesce is to ensure that if the left join returns no rows for a given Citation_ID value, that we replace the Null with zero.

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

Sidebar

Related Questions

I have just begun working with the Android SDK and I am having problems
I'm having problems working through how I would build times that increment by a
I am having problems with working with a third party XML string that contains
I'm having real problems getting PDO_MYSQL working. I started by just trying to install
I'm working on a semantic web project and I've encountered some problems about Uri
While working on an AppEngine connected Android project, I occasionally have problems with RequestFactory
I'm working on some homework for my compiler class and I have the following
So I am working on some homework and I have to complete a size
I'm working on my compiler homework and I have the following question: Consider the
I'm working on a homework assignment that asks me to create a calculator that

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.