我想让工作在最低和最高工资之间计算。 如果第一种情况满足,则跳过其余的情况条件。 任何人都可以建议我执行所有案件条件,即使第一个条件满足。
查询:
Job::selectRaw("(
CASE WHEN (
0 BETWEEN min_salary AND max_salary
OR 200000 BETWEEN min_salary AND max_salary)
THEN '0-2 Lacs'
WHEN (
'200000' BETWEEN min_salary AND max_salary OR '400000'
BETWEEN min_salary AND max_salary
)
THEN '2-4 Lacs' ELSE '4+' END) AS salaryrange,
count(*) as aggregate")
->groupBy('salaryrange')
->get();
工作表:
job_title min_salary max_salary
Job_1 150000 150000
Job_2 300000 800000
Job_3 150000 300000
Job_4 150000 500000
当前结果:
salaryrange aggregate
0-2 Lacs 2
2-4 Lacs 1
预期结果:
salaryrange aggregate
0-2 Lacs 2
2-4 Lacs 3