Trying to get the result in single row using sql?

前端 未结 5 1403
后悔当初
后悔当初 2021-01-29 15:00

I\'m trying to display all the employee id\'s

i need the result like

emp_id

10,11,12,13,14,15..,...

when tried

相关标签:
5条回答
  • 2021-01-29 15:38

    Try this:

    SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;
    
    0 讨论(0)
  • 2021-01-29 15:51

    Use LISTAGG function. Refer here for more in detail. Try like this,

    SELECT listagg(emp_id,',') WITHIN GROUP(ORDER BY emp_id) t 
    FROM   employees;
    
    0 讨论(0)
  • 2021-01-29 15:52

    try this

     declare @empid nvarchar(500)=''
        select @empid=@empid+Emp_id + ',' from tblemployee
        select substring(@empid,0,len(@empid)-1)
    
    0 讨论(0)
  • 2021-01-29 15:54

    For SQL try

     SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;
    

    Working demo at http://sqlfiddle.com/#!2/90dd2/1

    For Oracle

    SELECT LISTAGG(emp_id,',') WITHIN GROUP(ORDER BY emp_id) as emp_id 
    FROM   employees;
    

    demo at http://sqlfiddle.com/#!4/af004/9

    0 讨论(0)
  • 2021-01-29 15:57

    Try this

    SELECT CONCAT(emp_id,',') FROM employees;
    
    0 讨论(0)
提交回复
热议问题