Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query

Posted on 2014-03-04
4
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 500 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 41

Assisted Solution

by:Sharath
Sharath earned 500 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 500 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 500 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

618 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