Solved

query

Posted on 2014-03-04
4
195 Views
Last Modified: 2014-05-28
I have a data something like below:

mycol
---------
xyzmap
xyzjob1
xyztab2
xyztime
abcledger
abclicense
abctime
abcmap
pqrmap
pqrlinked
pqrtime

i want to derive a column where the value %map repeats for each group(abc, xyz,pqr)

mycol             mydercol
---------           -------------
xyzmap          xyzmap
xyzjob1          xyzmap
xyztab2          xyzmap
xyztime         xyzmap
abcledger      abcmap
abclicense    abcmap
abctime        abcmap
abcmap        abcmap
pqrmap        pqrmap
pqrlinked     pqrmap
pqrtime        pqrmap

is there a way to do this..

thanks
0
Comment
Question by:gs79
4 Comments
 
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 125 total points
ID: 39905648
it is not clear what do you mean by 'each group' but you could try this
SELECT substr(mycol, 1, 3) || 'map' mydercol FROM mytable

Open in new window

HTH
Ivo Stoykov
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 125 total points
ID: 39905656
try like this.
select t1.MyCol,t2.mydercol
  from test t1,
(select MyCol as mydercol,replace(MyCol,'map','') as MyCol1
  from test
 where MyCol like '%map') t2 where t1.MyCol like t2.MyCol1||'%'

Open in new window

http://sqlfiddle.com/#!4/408e1/9
0
 
LVL 34

Accepted Solution

by:
Mark Geerlings earned 125 total points
ID: 39908337
Is it always the first three characters that determines your "%map"?  If yes, then a simple query like this can do that for you: substr(mycol,1,3)||'map'.

You could create a view like this:
create or replace view map_view
(mycol, mydircol)
as select mycol, substr(mycol,1,3)||'map'
from your_table;
0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 125 total points
ID: 39920925
gs79,
You need to confirm or refute that the "group" is always the first three characters. If so, the concatenation already shown should work. If not, the task becomes a little more complex and will require further criteria for determining the "group".
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now