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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:10:25+00:00 2026-06-14T10:10:25+00:00

I am having some trouble with a query and was hoping someone could help.

  • 0

I am having some trouble with a query and was hoping someone could help. I have tried searching for a solution, but can’t seem to find a similar scenario with my search terms.

Here is what I am looking for:

I have a table with three columns and need to return the values in the first column, and two counts of the values in the second column. One count is based on a parameter and the other is the total count. Ideally, I would only like to return the values in column one that have equal counts.

For example:

Part Number | Make ID
ABC123      | 1<br>
ABC123      | 1<br>
ABC123      | 3<br>
DEF456      | 1<br>
DEF456      | 1

Part Number | Count of Apps Where Make ID = 1| Count of Total Apps
ABC123      |                              2 | 3
DEF456      |                              2 | 2

The query I have so far will return the total count of apps for part numbers that have the parameter value, but I need it to return both counts:

SELECT apps.part#, 
       COUNT(DISTINCT application#)apps 
FROM   [mytable] AS apps 
       INNER JOIN (SELECT part# 
                   FROM   [mytable] 
                   WHERE  make = '1') AS sz 
               ON sz.part# = apps.part# 
GROUP  BY apps.part# 
ORDER  BY 1 

Any help is greatly appreciated!

Thanks, everyone! I received several correct answers, and selected the one that was give first:

SELECT part#, 
       COUNT(DISTINCT CASE WHEN make = '1' THEN application# END) make1_apps,
       COUNT(DISTINCT application#) total_apps
FROM   [mytable]
GROUP  BY part#
HAVING COUNT(DISTINCT CASE WHEN make = '1' THEN application# END)
     = COUNT(DISTINCT application#)
ORDER  BY part#

Thanks again!

  • 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-14T10:10:26+00:00Added an answer on June 14, 2026 at 10:10 am
    SELECT part#, 
           COUNT(DISTINCT CASE WHEN make = '1' THEN application# END) make1_apps,
           COUNT(DISTINCT application#) total_apps
    FROM   [mytable]
    GROUP  BY part#
    HAVING COUNT(DISTINCT CASE WHEN make = '1' THEN application# END)
         = COUNT(DISTINCT application#)
    ORDER  BY part#; 
    

    The HAVING clause ensures the two counts match.

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

Sidebar

Related Questions

Am having some trouble with the SkyDrive download process and hoping you can help
I am having some trouble optimizing a query, and was hoping that someone here
I am having some trouble with a LINQ to dataset query. I have the
I'm having some trouble with a linq query. It's a simple problem, but I'm
I'm having some trouble writing a query. For example: Let's say I have just
I'm having some trouble with MySql right now. I have an query that works
I am having some trouble with a MySQL query. I have a field in
I am having some trouble building the query I need to return the AccountID
I'm having some trouble with finalizing my MySQL query. Imagine that i combine the
I'm having trouble with a query in SQL Server 2008 on some forex trading

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.