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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:02:28+00:00 2026-05-16T12:02:28+00:00

I have data in the following format in a table: Acct# Amount 123 3.4

  • 0

I have data in the following format in a table:

Acct#    Amount
123      3.4 
123T     4.5 
124      2.3 
124T     4.5 
125      1.2 
125T     2.4 

How do I create a select statement where it totals up the account number as 123+123T and gives the following output:

123    7.9
124    6.8
125    3.6
  • 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-16T12:02:28+00:00Added an answer on May 16, 2026 at 12:02 pm

    You don’t say any particular dialect of SQL

    SELECT LEFT(Acct#,3), SUM(Amount)
    FROM yourTable
    GROUP BY LEFT(Acct#,3)
    

    Or to handle arbitrary length account numbers

    SELECT
             CASE
                      WHEN Acct# LIKE '%T'
                      THEN SUBSTRING(Acct#,1,LEN(@Acct)-1)
                      ELSE Acct#
             END,
             SUM(Amount)
    FROM     yourTable
    GROUP BY
             CASE
                      WHEN Acct# LIKE '%T'
                      THEN SUBSTRING(Acct#,1,LEN(@Acct)-1)
                      ELSE Acct#
             END
    

    Or a more generic approach that will handle arbitrary mappings might be to construct a mapping table that you can then join on. There is quite a lot of missing information here as to the rules that need to be applied!

    SELECT d.b, SUM(yt.Amount)
    FROM yourTable yt
    join (
            SELECT '123' as a, '123' as b UNION ALL
            SELECT '123T' as a, '123' as b UNION ALL
            SELECT '124' as a, '124' as b UNION ALL
            SELECT '124T' as a, '124' as b UNION ALL
            SELECT '125' as a, '125' as b UNION ALL
            SELECT '125T' as a, '125' as b
    ) d ON d.a = yt.Acct#
    GROUP BY d.b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a log table with the following format (and sample data): date |
If I have data in the following format id subid text 1 1 Hello
I have a file in the following format: Data Data Data [Start] Data I
Hi I have following data in the table: ID-----startDate----endDate 5549 2008-05-01 4712-12-31 5567 2008-04-17
I have a sql table which have the following data, Id City Country ---
I have a php query the returns the following JSON format from a table.
I have the following data in my Street_Address_1 column: 123 Main Street Using Postgresql,
guys. Say I have the following table: ID | String ---+--------- 1 | <123><345>
I have a table with about 1.4 billion records, with the following format: mysql>
I have a table with the following data: Cell1 Cell2 Computers 10 Dell 5

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.