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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:43:38+00:00 2026-05-21T21:43:38+00:00

I have a table Competitor and here are some of its columns: Type |

  • 0

I have a table “Competitor” and here are some of its columns:

Type | Brand | Model | Date | Resolution | etc.

The table will have duplicate Model entries (with obviously same Brand as well, but possibly a different Type (two possible types: ‘ProAV’ and ‘Disti’)). I need to build a query that will output a table like this:

Top (ProAV) | Top (Disti) | Last Occurrence | Brand | Model | Resolution | etc.

Basically I need a query that will get a distinct type, brand, and model, but get a count of how many duplicates were found and put that number in either Top (ProAV) or Top (Disti), whichever Type it has. I would need to pull the most recent (given Date) out of the duplicates, so that I can put its Date as the Last Occurrence field. I hope this makes sense, let me know if it doesn’t.

  • 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-21T21:43:39+00:00Added an answer on May 21, 2026 at 9:43 pm
    SELECT SUM(CASE WHEN Type = 'ProAV' THEN 1 ELSE 0 END) AS TopProAV,
           SUM(CASE WHEN Type = 'Disti' THEN 1 ELSE 0 END) AS TopDisti,
           MAX(Date) AS LastOccurence,
           Brand, Model, Resolution
        FROM Competitor
        GROUP BY Brand, Model, Resolution
    

    EDIT: Based on the comment, you could use a subquery or CTE to accomplish what you want. Something like:

    WITH cteMaxDate AS (
        SELECT SUM(CASE WHEN Type = 'ProAV' THEN 1 ELSE 0 END) AS TopProAV,
               SUM(CASE WHEN Type = 'Disti' THEN 1 ELSE 0 END) AS TopDisti,
               MAX(Date) AS LastOccurence,
               Brand, Model, Resolution
            FROM Competitor
            GROUP BY Brand, Model, Resolution
    )
    SELECT md.TopProAV, md.TopDisti,
           md.LastOccurentce, 
           md.Brand, md.Model, md.Resolution,
           c.AdditionalColumn1, c.AdditionalColumn2
        FROM cteMaxDate md
            INNER JOIN Competitor c
                ON md.Brand = c.Brand
                    AND md.Model = c.Model
                    AND md.Resolution = c.Resolution
                    AND md.LastOccurence = c.Date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with some fields that the value will be 1 0. This
I have table of 5000+ rows and 8+ columns like, Station Lat Long Date
I have table with 3 columns A B C. I want to select *
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have the following tables: --table sportactivity-- sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time (tuple
I have table Players with columns: ID Name Points What is most efficient way
I have table named Table X which contains some names and their corresponding age,
I have table that has date field. When I run a query, I see
I have a large table (100000+ rows) in which are 4 columns of same
I have table of user actions, each having a user associated, a type, and

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.