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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:20:10+00:00 2026-06-15T13:20:10+00:00

Let’s say I have a table TableA : parent_id int this_id int filter int

  • 0

Let’s say I have a table TableA:

parent_id int
this_id int
filter int
this_date date

And some sample data:

parent_id = 1, this_id = 1, filter = 1, this_date = ...
parent_id = 1, this_id = 2, filter = 0, this_date = ...
parent_id = 1, this_id = 3, filter = 1, this_date = ...
parent_id = 4, this_id = 4, filter = 0, this_date = ...
parent_id = 4, this_id = 5, filter = 0, this_date = ...
parent_id = 4, this_id = 6, filter = 1, this_date = ...
parent_id = null, this_id = 7, filter = 0, this_date = ...
parent_id = null, this_id = 8, filter = 1, this_date = ...

The parent_id is always the same as one of the children’s this_id. If there are no children then parent_id is null

The table can’t change, that’s what we have.

I have created a view to give me summaries:

SELECT ISNULL(parent_id,this_id) id, COUNT(*) numparts, MAX(this_date)...
FROM TableA
GROUP BY ISNULL(parent_id,this_id)

I want to add to my summary view the number of parts that have filter=1.

So my results for this example (if I do a SELECT * FROM theview) would be:

id  numparts dt    numOfFilter1
1      3     ...        2
4      3     ...        1
7      1     ...        0
8      1     ...        1

In reality my filter column will be a sub-query but I think I can figure that bit out once I have this bit sorted.

  • 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-15T13:20:11+00:00Added an answer on June 15, 2026 at 1:20 pm

    Try it like this:

    SELECT  ISNULL(parent_id,this_id) id, 
            COUNT(*) numparts, 
            MAX(this_date), 
            SUM(CASE WHEN filter = 1 THEN 1 ELSE 0 END) numOfFilter1
    FROM    TableA
    GROUP BY 
            ISNULL(parent_id,this_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some data in a CouchDB database. The overall size is
Let's say I have a table with a Color column. Color can have various
Let's say that I have a date in R and it's formatted as follows.
Let's say I'm building a data access layer for an application. Typically I have
Let's say I have a due date and a reminder timespan . How do
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012
Let's say that I have classes like this: public class Parent { public int
Let's say I have 2 functions: void function1(int *ptr) { printf(%d, *ptr); } and
Let's say I have a table that lists various toys and the types of

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.