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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:07:17+00:00 2026-05-12T09:07:17+00:00

If I had a table like this: jobId, jobName, Priority Whereby Priority can be

  • 0

If I had a table like this:

jobId, jobName, Priority

Whereby Priority can be an integer between 1 to 5.

Since I would need this query for generating a chart on report, I would need to display the jobid, jobname and 5 fields called Priority1, Priority2, Priority3, Priority4. Priority5.

Priority1 should count the amount of rows where priority field has the value of 1.

Priority2 should count the amount of rows where priority field has the value of 2.

Priority3 should count the amount of rows where priority field has the value of 3.

etc

How would I do that in a quick and performant manner?

  • 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-12T09:07:18+00:00Added an answer on May 12, 2026 at 9:07 am

    I think you may be after

    select 
        jobID, JobName,
        sum(case when Priority = 1 then 1 else 0 end) as priority1,
        sum(case when Priority = 2 then 1 else 0 end) as priority2,
        sum(case when Priority = 3 then 1 else 0 end) as priority3,
        sum(case when Priority = 4 then 1 else 0 end) as priority4,
        sum(case when Priority = 5 then 1 else 0 end) as priority5
    from
        Jobs
    group by 
        jobID, JobName
    

    However I am uncertain if you need to the jobID and JobName in your results if so remove them and remove the group by,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a table like this id | name ------------------ 1 | SAM1 2
I had table like this: post: +----------------+-----------+ | article_id | tags | +----------------+-----------+ |
I had a query like this select count(distinct sessionKey) as tot from visits But
I have a simple table structure like this. What I would like to do
I'm having problems trying to get a query like this table answers CREATE TABLE
If I had a CarsDataStore representing a table something like: Cars -------------- Ford |
I had a simple table: class test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True)
I got problem with core data, I had a table that exactly look like
SCENARIO: Imagine a TABLE like this: Auto_INC, UserID_FK, CaseID_FK, Date idX userX caseX and
Suppose you had this table: CREATE TABLE Records ( RecordId int IDENTITY(1,1) NOT NULL,

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.