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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:57:35+00:00 2026-05-13T22:57:35+00:00

First of all, I don’t want to use a join because that will make

  • 0

First of all, I don’t want to use a “join” because that will make my query longer and difficult to read. So what I need to do must be withing the same SELECT statement.

My columns in myTable are A, B , C , D , time, ID and H

H columnd tells if a record is ‘Open’ or ‘Close’, here how my query looks like.

SELECT 
A, 
B, 
C, 
D,
COUNT(DISTINCT ID) AS numberOfRecords,
SUM(time) / COUNT(DISTINCT ID) AS averageTimeOfAllRecords   
FROM myTable
WHERE ISNUMERIC(A)=1 AND A IN (SELECT A FROM myTable2)
GROUP BY A,B,C,D

I need the query above to return another column with a result: COUNT(DISTINCT ID) WHERE H = ‘Open’ so that I can get numberOfOpenRecords.

I can’t write my new condition to my “WHERE”, because that will effect the results, like numberOfRecords.

Hope I explained my problem.

Thanks for helps.

  • 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-13T22:57:35+00:00Added an answer on May 13, 2026 at 10:57 pm

    Since count doesn’t count null values, you could:

    count(distinct case when H = 'Open' then id else null end)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all. I want to say that i've acctualy read the other posts
Ok, first of all I don't want to use Boost, or any external libraries.
First of all, I want to say that I'm huge on theory. I don't
First of all, I don't want to use any framework but I am looking
First of all I don't know if this is the right approach. I want
First of all, I don't want an algorithm like A*, Dijkstra or something like
First of all, I believe , it's not a duplicate question. I don't want
First of all I'd like to precise that I've read all the jQuery called
First of all, I really don't want anyone to do my assignment. I just
First of all, I have read the similar posts and don't see how they

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.