In Oracle SQL, how can I display a blank row between every unique row? -
suppose have simple query like:
select employee, item_type, count(item_type) hr_database
so output may like
bob mugs 4 bob pencils 10 cat mugs 2 cat paperclips 7 sal mugs 11
but readability, want put blank row between each user in output(i.e readability), :
bob mugs 4 bob pencils 10 cat mugs 2 cat paperclips 7 sal mugs 11
is there way in oracle sql ? far, i found link doesn't match need . i'm thinking use in query?
thanks !
you can in database, type of processing should done @ application layer.
but, kind of amusing trick figure out how in database, , specific question:
with e ( select employee, item_type, count(item_type) cnt hr_database group employee, item_type ) select (case when cnt not null employee end) employee, item_type, cnt (select employee, item_type, cnt, 1 x e union select distinct employee, null, null, 2 x e ) e order e.employee, x;
i emphasize, though, amusement , perhaps understanding better how sql works. in real world, type of work @ application layer.
a summary of how works. union all
brings in 1 additional row each employee. x
priority sorting -- because have sort result set proper ordering. case
statement needed prevent employee
being in first column. cnt
should never null
valid rows.
Comments
Post a Comment