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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:28:21+00:00 2026-05-23T10:28:21+00:00

I have a table like so: id | userid | operation_id | category |

  • 0

I have a table like so:

id | userid | operation_id | category | date
===============================================
1   bobdole   2              Major      2011-02-20
2   bobdole   3              Major      2011-02-20
3   bobdole   2              Minor      2011-02-20
4   bobdole   2              Minor      2011-02-20
5   bobdole   2              Minor      2011-02-21
6   not_bob   2              Minor      2011-02-21

And I would like to write a query so that each record comes up with the number of Major and minor faults per day per person. eg:

userid  | operation_id | Major faults| Minor faults | date
=================================================================
bobdole   2              1            2             2011-02-20
bobdole   3              1            0             2011-02-20
bobdole   2              0            1             2011-02-21
not_bob   2              0            1             2011-02-21

How do I say that I’d like a count the user id, operation_id, count of faults that = “Major”, a count of faults that = “Minor” and grouped by date?

Here is what I tried:

SELECT employee, operation_id, date_entered, orgin, grading, 
       COUNT(grading = "Major"), count(grading = "Minor") 
  FROM faults 
  JOIN company.tblusers on faults.employee = compeny.tblusers.sugar_name 
 WHERE ncr_ncr.date_entered > date("2011-01-01")
   AND protocase.tblusers.departmentid = 8
   AND orgin != "unknown" 
   AND orgin != "Unknown"
   AND orgin IS NOT NULL
GROUP BY employee, date_entered, operation_id

EDIT: This worked:

select 
  employee, 
  userid,
  operation_id, 
  date(date_entered), 
  orgin,  
  SUM(case when grading = 'Major' then 1 else 0 end), 
  SUM(case when grading = 'Minor' then 1 else 0 end) 
from ncr_ncr 
join company.tblusers on ncr_ncr.employee = company.tblusers.sugar_name 
where 
ncr_ncr.date_entered > date("2011-01-01") 
and company.tblusers.departmentid = 8
and orgin != "unknown" 
and orgin != "Unknown"
and date_entered is not null
and orgin is not null
AND(grading = "Minor" or grading = "Major")
group by employee, date(date_entered), operation_id
order by date(date_entered), employee, operation_id
  • 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-23T10:28:22+00:00Added an answer on May 23, 2026 at 10:28 am
    select 
      userid, operationid,
      sum(case category when 'Major' then 1 else null end) MajorFaults,
      sum(case category when 'Minor' then 1 else null end) MinorFaults,
      date
    from YourTable
    group by userid, operationid, date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this UserID Score Date 5 6 2010-1-1 7 8
I have a table with weekly data that looks like: userID Site date ------
i have a table which Data is like userID name amount Date 1 mark
I have a table like this: ActionTime UserID Score 2011-08-15 12:06:00 1 14 2011-08-15
I have a database with one table, like so: UserID (int), MovieID (int), Rating
I have UserScores Table with data like this: Id userId Score 1 1 10
I have a table like this: UserID Customer ID status 1 1 1 1
Lets say I have a database table called Scrape possibly setup like: UserID (int)
I have a sql table called UsersInAuthentication like ----------------------- | AuthUserId | UserId |
I have a table like the following table: UserID Num1 Num2 Code Name Cat

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.