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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:08:27+00:00 2026-05-25T23:08:27+00:00

I have a tableA (ID int, Match varchar, tot int) ID Match Tot 1

  • 0

I have a tableA (ID int, Match varchar, tot int)

ID Match Tot
1  123
2  123
3  12
4  12
5  4
6  12
7  8

Now, I want to calculate Tot which is total number of match exists in the table. for example 123 occured twice, 12 exist thrice and so on. Also note that I want the count only at first match. here is the expected result.:

ID Match Tot
1  123    2
2  123
3  12     3
4  12
5  4      1
6  12
7  8      1

Another case:

    ID Match Count Tot
    1  123   2
    2  123   1
    3  12    10
    4  12    10
    5  4     3
    6  12    5
    7  8     7

Now I want to add the count for the same match. expected result:

    ID Match Count Tot
    1  123   2      3
    2  123   1
    3  12    10     25
    4  12    10
    5  4     3       3
    6  12    5  
    7  8     7       7

Thanks

  • 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-25T23:08:27+00:00Added an answer on May 25, 2026 at 11:08 pm
    WITH tableA(ID, Match) AS
    (
    SELECT 1,123 UNION ALL
    SELECT 2,123 UNION ALL
    SELECT 3,12 UNION ALL
    SELECT 4,12 UNION ALL
    SELECT 5,4 UNION ALL
    SELECT 6,12 UNION ALL
    SELECT 7,8
    )
    SELECT *,
           CASE
             WHEN ROW_NUMBER() OVER (PARTITION BY Match ORDER BY ID) = 1 
             THEN COUNT(*) OVER (PARTITION BY Match)
           END AS Tot
    FROM   tableA
    ORDER  BY ID  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with following fields id (int) name (varchar) dob (datetime) Now
I have a tableA (ID int, Match varchar, code char, status = char) ID
I have this table (TableA): ( [FieldA] [int] NOT NULL, [FieldB] [int] NOT NULL,
I have the following tables: create table TableA ( Id int primary key identity,
I have two tables which looks something like this Table Queue int ID; string
I have three tables: articles(id int) tags(id int, name varchar(255)) articles_tags(article_id, tag_id) I want
I have a table with two columns: price (int) and price_display (varchar). price is
I have a table, InnoDB, with columns id(int), name(varchar) and info(text). I need to
Have two tables: CREATE TABLE IF NOT EXISTS `issue_details` ( `id` INT NOT NULL
I have two tables: ( ID = int, Match = varchar, Status = char

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.