仅显示一次列值

时间:2019-05-29 07:25:35

标签: oracle

我有这样的数据:

enter image description here

我想这样显示

enter image description here

所有员工的职位都与经理相同,但我想显示一次。

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作,但仅应出于显示目的:

WITH a (ename, position, deptno) AS (SELECT 'KING', 'Manager', 10 FROM dual 
                                     UNION ALL 
                                     SELECT 'BLAKE', 'Manager', 30 FROM dual 
                                     UNION ALL 
                                     SELECT 'CLARK', 'Manager', 10 FROM dual 
                                     UNION ALL 
                                     SELECT 'ALLEN', 'Manager', 30 FROM dual 
                                     UNION ALL 
                                     SELECT 'WARD', 'Manager', 30 FROM dual)
SELECT ENAME
     , CASE WHEN position = MAX(position) over (ORDER BY ROWNUM 
                                                 ROWS BETWEEN 1 preceding AND 1 preceding) 
            THEN NULL 
            ELSE position 
       END position
     , deptno 
  FROM a 

如果值与上一行相同,则将在列NULL中显示POSITION