Conditional Count on a field

前端 未结 8 1806
庸人自扰
庸人自扰 2020-11-28 06:55

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 que

相关标签:
8条回答
  • 2020-11-28 07:30

    Try this:

    SELECT Count(Student_ID) as 'StudentCount' 
    FROM CourseSemOne
    where Student_ID=3 
    Having Count(Student_ID) < 6 and Count(Student_ID) > 0;
    
    0 讨论(0)
  • 2020-11-28 07:39

    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 讨论(0)
提交回复
热议问题