Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Oracle/SQL how to select rows where the value of the columns remained the same

In Oracle/SQL how to select rows where the value of the columns remained the same

I have a list of budget, each budget spread over 12 months, with fixed salary each month. I would like to return a list of budgets for which the value of the salary remained the same over 12 months.

BUDGET MONTH SALARY
5468 1              1500
5468 2              1500
5468 3              1500
5468 4              1500
5468 5              1500
5468 6              1500
5468 7              1500
5468 8              1500
5468 9              1500
5468 10             1500
5468 11             1500
5468 12             1500

3456 1              1675
3456 2              1675
3456 3              1675
3456 4              1675
3456 5              1500
3456 6              1500
3456 7              1500
3456 8              1500
3456 9              1675
3456 10             1675
3456 11             1675
3456 12             1675

3948 1              2900
3948 2              2900
3948 3              2900
3948 4              2900
3948 5              2900
3948 6              2900
3948 7              2900
3948 8              2900
3948 9              2900
3948 10             2900
3948 11             2900
3948 12             2900

9756 1              2900
9756 2              2900
9756 3              2900
9756 4              2900
9756 5              2900
9756 6              2900
9756 7              2900
9756 8              2900
9756 9              2900
9756 10             2900
9756 11             2900
9756 12             2900

9712 1              2743
9712 2              2900
9712 3              2900
9712 4              2900
9712 5              2743
9712 6              2900
9712 7              2743
9712 8              2900
9712 9              2900
9712 10             2743
9712 11             2900

5394 1              1500
5394 2              1500
5394 3              1500
5394 4              1500
5394 5              1500
5394 6              1500
5394 7              1500
5394 8              1500
5394 9              1500
5394 10             1500
5394 11             1500
5394 12             1500
like image 314
Jean-Luc Avatar asked Mar 18 '23 22:03

Jean-Luc


1 Answers

Count the distinct salary for every budget

select budget
from your_table
group by budget
having count(distinct salary) = 1
like image 168
juergen d Avatar answered Mar 20 '23 14:03

juergen d