Sql 分组数据填充

Sql 分组数据填充,sql,plsql,Sql,Plsql,我在Report中工作,希望在组中只显示一次顺序 我尝试过使用loop并将值赋给temp变量,然后进行比较 declare l_cnt number; cursor c1 is select * from zz_employees; begin dbms_output.put_line ('Order |-' || 'Material | -' || 'Salesperson |'); for i in c1 loop l_cnt := i.ordernumber; if l_cnt =

我在Report中工作,希望在组中只显示一次顺序

我尝试过使用loop并将值赋给temp变量,然后进行比较

declare
l_cnt number;
cursor c1 is select * from zz_employees;
begin
dbms_output.put_line ('Order |-' || 'Material | -' || 'Salesperson |');
for i in c1
loop
  l_cnt := i.ordernumber;
  if l_cnt = i.ordernumber then 
        --dbms_output.put_line (l_cnt);
         dbms_output.put_line (l_cnt || '-' || i.materialno || '-' || i.salesperson);
  else
  dbms_output.put_line (i.ordernumber || '-' || i.materialno || '-' || i.salesperson);
  end if;
end loop;
end;
当前表格数据:-

1001    9000001 James
1001    9000002 Tom
1001    9000003 Harry
1002    9000004 Voret
1002    9000005 Kzahunar
1003    9000006 Zari
1004    9000007 Neblas
1004    9000008 Anthony
预期结果

1001    9000001 James
        9000002 Tom
        9000003 Harry
1002    9000004 Voret
        9000005 Kzahunar
1003    9000006 Zari
1004    9000007 Neblas
        9000008 Anthony

打印值时,无论发生什么情况,都必须稍微更改循环:

loop
  if l_cnt = i.ordernumber then 
    dbms_output.put_line ('    -' || i.materialno || '-' || i.salesperson);
  else
    dbms_output.put_line (i.ordernumber || '-' || i.materialno || '-' || i.salesperson);
    l_cnt := i.ordernumber;
  end if;
end loop;
或者,您可以直接在查询中输入值:

SELECT CASE WHEN ordernumber  = MAX(ordernumber) over (ORDER BY ROWNUM 
                                                 ROWS BETWEEN 1 preceding AND 1 preceding) 
            THEN NULL 
            ELSE ordernumber  
       END ordernumber 
     , materialno 
     , salesperson
  FROM zz_employees

这两种解决方案都按预期工作。。非常感谢你!