如何在sql中显示序列号

问题描述 投票:0回答:1

如何显示以下序列号

select count(*) toatl_count, "employee is Invalid" error from emp
union
select count(*) total_count, "comapny name is incorrect" error from company;

结果将会是

total_count error
10          employee is Invalid
55          comapny name is incorrect

但我需要如下输出

serial number total_count error
     1         10          employee is Invalid
     2        55          comapny name is incorrect
sql plsql
1个回答
0
投票

试试这个:

SELECT 
  ROW_NUMBER() OVER() AS serial_no,
  total_count, 
  error
FROM (
  SELECT count(*) total_count, '"employee is Invalid"' error FROM emp
  UNION
  SELECT count(*) total_count, '"company name is incorrect"' error FROM company
) subquery
ORDER BY serial_no;
© www.soinside.com 2019 - 2024. All rights reserved.