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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:29+00:00 2026-05-23T08:44:29+00:00

Three tables cats ============= id cat_herder_id size color birthday collars ============= id cat_id diameter

  • 0

Three tables

cats
=============
id
cat_herder_id
size
color
birthday

collars
=============
id
cat_id
diameter
color
material

cat_herders
=============
id
name
age
height

I want to get a row for each cat herder that is over a meter tall with a count of the number of cats that were born in February that are orange with black collars that belong to that herder and a count of all the cats that are orange with blue collars the belong to each herder, how would I go about doing a query of that sort.

I don’t think I can simply specify in the where statement because my count appears to be off, I am grouping by cat_herders.id

EDIT: Less sanitized, less abstracted version of what I have so far:

SELECT company.tblusers.first_name, company.tblusers.last_name, company.tblusers.userid, SUM(db.tasks.estimated_nonrecurring+db.tasks.estimated_recurring), COUNT(sugarcrm2.ncr_ncr.id),  
SUM(db.batch_log.time_elapsed) FROM company.tblusers 
INNER JOIN db.batch_log ON company.tblusers.userid = db.batch_log.userid 
INNER JOIN db.tasks ON db.batch_log.batch_id = db.tasks.batch_id
INNER JOIN sugarcrm2.ncr_ncr ON company.tblusers.first_name + " " + company.tblusers.first_name = sugarcrm2.ncr_ncr.employee
WHERE  departmentid = 8 AND DATE(db.batch_log.start_time) =  DATE(NOW()) GROUP BY userid
  • 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-23T08:44:30+00:00Added an answer on May 23, 2026 at 8:44 am

    Note: Depending on your RDBMS and the datatype of the cats.birthday column, you’ll probably need to adjust this query to extract the birth month, but this gives you the general idea.

    SELECT ch.name,
           SUM(CASE WHEN c.color = 'orange' AND cl.color = 'black' AND c.birthday = 'February' THEN 1 ELSE 0 END) AS OrangeCatsBlackCollarsFeb,
           SUM(CASE WHEN c.color = 'orange' AND cl.color = 'blue' THEN 1 ELSE 0 END) AS OrangeCatsBlueCollars 
        FROM cat_herders ch
            LEFT JOIN cats c
                INNER JOIN collars cl
                    ON c.id = cl.cat_id
                ON ch.id = c.cat_herder_id
        WHERE ch.height > 1 /* in meters */
        GROUP BY ch.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got three tables CATS id name ------------------------------ 1 category1 2 category2 3 category3
Suppose I have three tables in my Rails app: cats , dogs , and
Using Access 2010. Suppose I have three tables: dogs , cats , and catChases
I have three tables: Employee(Id,name etc) Appointment(Id,date,time,employee id, clientid etc) Client(Id,name etc) The Employee
I have three tables like this: Person id | name | location ----------------------- 1
I have three tables like these: movie: id, name tag: id, name, value tagged:
I have three tables: CREATE TABLE person (id int, name char(50)) CREATE TABLE eventtype
This has been driving me mad. I have three tables: items ID name type
I have three tables: `brands` (`id`, `name`) `categories` (`id`, `name`) `products` (`id`, `name`, `brand_id`,
Consider three tables: one of items, one of tags on those items, and the

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.