Link to home
Start Free TrialLog in
Avatar of mohammadzahid
mohammadzahidFlag for Canada

asked on

Data Formatting Question

Hi All,

I'm not sure how to do data formatting using a SQL Statement in Oracle database.

Is it possible to have output from a SQL statement appear like (see attached) or in an excel format using a pivot table?
EE-Question.xlsx
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Oracle also has a PIVOT ability.

You have to have a known set of columns so based on the data, I guessed that it was the tire location.  I got that with a SUBSTR on position.

See if this works for you:
select * from (
   select asset, status, position, tire, substr(position,6) pivot_col
   from tab1 t
)
pivot 
(
   max(position) max_pos,
   max(tire) max_tire
   for pivot_col in ('LCI','LCO','LF','LRI','LRO','RCI','RCO','RF','RRI','RRO')
)
/

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial