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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:25:40+00:00 2026-06-12T16:25:40+00:00

I have below table with Boolean column has_object which indicate each row has associated

  • 0

I have below table with Boolean column has_object which indicate each row has associated digital object or not.

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| pid        | varchar(255) | NO   | PRI |         |       |
| title      | text         | YES  |     | NULL    |       |
| owner_uid  | int(11)      | YES  |     | NULL    |       |
| has_object | int(11)      | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+

I have tried this query to obtain statistical information about each owner_uid. but in my table it returns wrong result:

SELECT 
  a.owner_uid, 
  count(b.pid) as count1, 
  count(c.pid) as count2  
FROM
  islandora_report a
  JOIN islandora_report b ON b.owner_uid = a.owner_uid AND b.has_object = 0
  JOIN islandora_report c ON c.owner_uid = a.owner_uid AND c.has_object = 1
GROUP BY a.owner_uid;

The result:

enter image description here

  • 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-12T16:25:42+00:00Added an answer on June 12, 2026 at 4:25 pm

    Since the BOOLEAN is merely a 0 or 1, you can actually do one pair of SUM() without any joins to add up the column.

    SELECT
      owner_uid,
      /* SUM() adds up all the 1 values */
      SUM(has_object) AS count_true,
      /* Invert the boolean with a case statement to get the inverse */
      SUM(CASE WHEN has_object = 1 THEN 0 ELSE 1 END) AS count_false
    FROM islandora_report
    GROUP BY owner_uid
    

    There are other ways to invert the boolean than the method above. It’s just the first that came to mind. You could also subtract the true sum from the total count, for example:

    SUM(has_object) AS count_true,
    COUNT(*) - SUM(has_object) AS count_false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic List object which hold below table as its own value.
I have a table which contains many rows, each with a column named RecordData
I have the below table. I am trying to get tbody column bgcolors matching
I have the below column on my table what gets binded on pageload, the
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a table with four columns, and I would like each column head
I have a table in mysql databse with a boolean column (or tinyint(1)). In
I have a table like below: Table A ---------- ID Field1 Field2 Field3 1
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr
I have a mysql database with a table structure like below : Table Name

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.