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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:06:25+00:00 2026-06-01T07:06:25+00:00

MY_TABLE = Table with 2 columns Number, City. Desired Output = City and count

  • 0

MY_TABLE = Table with 2 columns Number, City.
Desired Output = City and count of unique Number associated to the city. Seattle, Bellevue is part of Combined. Even though there are 4 numbers associated to Seattle, Bellevue the output is 3 as there are only 3 distinct numbers – 123, 456, 786.

  MY_TABLE
Number   City
123  Seattle
456  Bellevue
789  LosAngeles
780  LosAngeles
123  Bellevue
786  Bellevue

Desired Output:

Combined 3
LosAngeles 2

Query so far:

SELECT NUMBER, CITY FROM MY_TABLE WHERE LOOKUP_ID=100 AND CITY IN 
('Seattle', 'Bellevue', 'LosAngeles')
GROUP BY NUMBER, CITY

Would highly appreciate if anyone provides a recommendations around the same.

  • 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-01T07:06:27+00:00Added an answer on June 1, 2026 at 7:06 am

    You could do something like

    SELECT (case when city IN ('Seattle', 'Bellevue') 
                 then 'Combined'
                 else city
              end) city,
           count( distinct number ) 
      FROM my_table
     WHERE lookup_id = 100
       AND city IN ('Seattle', 'Bellevue', 'LosAngeles')
     GROUP BY (case when city IN ('Seattle', 'Bellevue') 
                    then 'Combined'
                    else city
               end) 
    

    Of course, my guess is that you have some other table that tells you which CITY values need to be combined rather than having a hard-coded CASE statement.

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

Sidebar

Related Questions

My table has a large number of columns. I have a command to copy
My SAMPLE table has the following five columns: sample_id (PK) (NUMBER) sampled_on (DATE) received_on
My output for my table in HTML has several columns such as userid, name,
I have a table with many two columns: id, mydate Id is a number;
These are my table's columns: contact_id, contact_number I have one number to search in
I have to render a complex table with variable number of columns. In this
I need to add indexes to my table (columns) and stumbled across this post:
I have three columns in my table - company_name, first_name, last_name . In the
One of the columns in my table is a varchar that is supposed to
I have two columns in my table and the rows are created dynamically. <table

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.