Solved

query

Posted on 2014-03-04
4
198 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 35

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 32

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

820 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