user8340125
user8340125

Reputation:

Formatting columns in sql

How do I format the code to have blanks instead of the managers name each time?

Select Manager, Employee From Work

enter image description here

enter image description here

Upvotes: 0

Views: 57

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271091

There is no easy way to do this, because this type of processing is not really suitable for relational databases. Why? The result set depends entirely on ordering -- and SQL works with unsorted sets.

It is possible. Here is one method:

select (case when employee is null then manager end) as manager,
       employee
from ((select distinct manager, NULL as employee from work) union all
      (select manager, employee from work)
     ) me
order by manager, (case when employee is null then 1 else 2 end), employee;

However, I advise you to do this in the application layer rather than the database.

Upvotes: 2

Related Questions