In Oracle / SQL, how to select rows where column value remained the same

In Oracle / SQL, how to select rows where column value remained the same

I have a budget list, each budget is spread over 12 months with a fixed salary every month. I would like to return a list of budgets that have remained the same for 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

      

+3


source to share


3 answers


Calculate the salary distinct

for each budget



select budget
from your_table
group by budget
having count(distinct salary) = 1

      

+3


source


SELECT BUDGET,SALARY FROM BUDTGET_TAB
HAVING COUNT(MONTH)=12
GROUP BY BUDGET,SALARY
ORDER BY 1,2

      



+2


source


SELECT BUDGET,SALARY FROM BUDTGET_TAB
GROUP BY BUDGET,SALARY
HAVING COUNT(MONTH)=12
ORDER BY 1,2;

      

I just rebuilt a query that was written by Dharmesh ...

+1


source







All Articles