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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:39:53+00:00 2026-05-23T14:39:53+00:00

I am wrote this SQL: select distinct PayID, PaymentDate, AccountNumber, sum(PaymentAmount) as Amount from

  • 0

I am wrote this SQL:

select distinct PayID, PaymentDate, AccountNumber, sum(PaymentAmount) as Amount 
from tblInvoicePaymentDetails 
where CustomerID = 'mud4978' 
group by PayID, PaymentDate, AccountNumber

Output is:

PayID    PayDate                    Account      Amount
1        2011-07-05 11:09:14.390    NULL       700.00
1        2011-07-05 11:09:14.407    NULL       100.00
2        2011-07-05 11:20:05.517    NULL       0.00
2        2011-07-05 11:20:05.547    9000       500.00
2        2011-07-05 11:20:07.000    9000       100.00
3        2011-07-05 12:19:22.017    100000     200.00
3        2011-07-05 12:19:22.077    100000     100.00

But my requirements are to display 3 records (avoid duplicates) and sum of amount like this:

payid         paydate             account       amount
1           2011-07-05 11:09:14   null          800.00
2           2011-07-05 11:20:05   9000          600.00
3           2011-07-05 12:19:22   100000        300.00

please 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-05-23T14:39:54+00:00Added an answer on May 23, 2026 at 2:39 pm

    It looks like you only want to group by PayID (otherwise other columns will be taken into account).

    PayDate varies, so if you want one of those values you need to pick which exact PayDate you want in your output. You may wish to consider Max or Min to pick one that exists already.

    Account also varies, so again you need to pick one using something like Min or Max

    Your query would then look something like this:

    SELECT DISTINCT 
        PayID, 
        MIN(PaymentDate) AS PaymentDate, 
        MAX(AccountNumber) as AccountNumber, 
        SUM(PaymentAmount) as Amount 
    FROM tblInvoicePaymentDetails 
    WHERE CustomerID='mud4978' 
    GROUP BY PayID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write this query in SQL Server from ( select DISTINCT salary from
I have a query that, basically, says this: SELECT DISTINCT [DB_ID] FROM [TableX] WHERE
I wrote this SQL server select statement to only return 204 characters and append
This is SQL query I wrote, it work fine but it is slow. SELECT
So I have this SQL query, <named-query name=NQ::job_exists> <query> select 0 from dual where
I write a stored procedure in SQL Server like this select distinct top 5
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer
What's the best way to do something like this in T-SQL? SELECT DISTINCT ID
I have a simple SQL statement. Select distinct value from tablename where value not
When I write an SQL statement, I usually write it like this SELECT COUNT(*)

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.