我正在尝试显示所有员工ID
我需要像
这样的结果emp_id
10,11,12,13,14,15..,...
尝试时
SELECT LISTAGG(emp_id, ',') WITHIN GROUP (ORDER BY emp_id) AS ID FROM employees GROUP BY emp_id;
我收到错误
ORA-00923: FROM keyword not found where expected
这里的问题在哪里?
答案 0 :(得分:1)
使用LISTAGG
功能。有关详细信息,请参阅here。试试这样,
SELECT listagg(emp_id,',') WITHIN GROUP(ORDER BY emp_id) t
FROM employees;
答案 1 :(得分:0)
试试这个
SELECT CONCAT(emp_id,',') FROM employees;
答案 2 :(得分:0)
试试这个
declare @empid nvarchar(500)=''
select @empid=@empid+Emp_id + ',' from tblemployee
select substring(@empid,0,len(@empid)-1)
答案 3 :(得分:0)
对于SQL,请尝试
SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;
http://sqlfiddle.com/#!2/90dd2/1
的工作演示对于Oracle
SELECT LISTAGG(emp_id,',') WITHIN GROUP(ORDER BY emp_id) as emp_id
FROM employees;
答案 4 :(得分:0)
试试这个:
SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;