sql oracle - remove duplicate value

那年仲夏 提交于 2021-01-29 15:05:50

问题


I have the below query, it returns the column UP that contents duplicated values (for example '111' exists 5 times but not all of them have a value in CODE_DEPT)

select  UP, CODE_DEPT from ESP_ENSEIGNANT;

UP    CODE_DEPT
111     f
555
111
222     y
222
111
444
666
222
444     k
111     f
111     
666     x

so i want to update my query to get a unique UP with CODE_DEPT (if CODE_DEPT is not empty it returns else it returns empty)

UP    CODE_DEPT
111     f
555
222     y
444     k
666     x

回答1:


You can use aggregation:

select up, max(code_dept) as code_dept
from ESP_ENSEIGNANT ee
group by up;


来源:https://stackoverflow.com/questions/65708761/sql-oracle-remove-duplicate-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!