Query to group dept codes in a row
Hi Gurus,
I am trying to write a sql to list all the employees and their dept codes in duration of 5 years.
I have a table like
Emp Dept_codes
1 10,20,40
1 30,50
2 10,40
2 30
3 70
EMp and Dept_codes are character types.
Is it possible to have a solution like
Emp Dept_codes
1 10,20,30,40,50
2 10,30,40
3 70
Please let me know if this is possible using a SQL stmt.
Thanks in advance.
The question is not about the data modelIt's all about the data model, you wouldn't have such difficulties if the data model would be normalized.
Anyway, try this, it is a combination of algorithms described here and here
SQL> SELECT emp,
2 LTRIM(MAX(SYS_CONNECT_BY_PATH(dept_code,','))
3 KEEP (DENSE_RANK LAST ORDER BY curr),',') AS dept_codes
4 FROM (SELECT emp,
5 dept_code,
6 ROW_NUMBER() OVER (PARTITION BY emp ORDER BY dept_code) AS curr,
7 ROW_NUMBER() OVER (PARTITION BY emp ORDER BY dept_code) -1 AS prev
8 FROM (SELECT emp,
9 EXTRACTVALUE(xt.column_value,'e') dept_code
10 FROM t,
11 TABLE(XMLSEQUENCE
12 ( EXTRACT
13 ( XMLTYPE('<coll><e>' || REPLACE(dept_codes,',','</e><e>') || '</e></coll>')
14 , '/coll/*')
15 )) xt
16 )
17 )
18 GROUP BY emp
19 CONNECT BY prev = PRIOR curr AND emp = PRIOR emp
20 START WITH curr = 1;
EMP DEPT_CODES
1 10,20,30,40,50
2 10,30,40
3 70
SQL>
Similar Messages
-
Need a query to merge output in a single row?
Hi All,
I need a query to merge output in a single row.
Query :
Select dname from dept.
Actual output is :
Dname
EDP
ACCOUNT
GR
Desired Output is:
Dname
EDP ACCOUNT GR
Please provide me the solution
Thanks
Amitselect max(sys_connect_by_path (t.name,' ')) from ( select id,
name,
group_id,
row_number() over (partition by group_id order by id) rn
from ( select 1 id, 'test' name, 1 group_id from dual
union
select 2 id, 'test1' name, 1 group_id from dual
union
select 3 id, 'test2' name, 1 group_id from dual
union
select 4 id, 'test3' name, 1 group_id from dual) ) t
start with t.rn = 1 and id = 1
connect by t.rn = prior t.rn + 1
group by t.group_id -
Query Designer - Query:Specialist Group Status
Hi Gurus,
One of my BI user is getting error in this:
In Query Designer - Query:Specialist Group Status
"Registered JIT debugger is not avialable. An attempt to launch a JIT debugger with the following
command resulted in an error code of 0x2(2). please check computer settings.
cordbg.exe !a 0x289c"
but when I tried with SUPER USER access i am not getting above error.
Guys please suggest me asap
Thanks
sahadhello,
Check the variabledefinitions of the query.
Try RSRT and 'execute and debug'.
It might be you get a lot more detailed information about the problem.
see OSS note 961995.
Regards,
Dhanya -
Crosstab Query re Grouping Data into Value Ranges
Hi
I am trying to analyse some data in a Crosstab & have a query re grouping.
The data contains sales transaction info such as selling price, quantity etc. I would like to create a grouping in the Crosstab based on a sale price range (eg £0 - £10, £10 - £20 etc) so that I can show the total quantity sold in each price range.
To date my method has been to create a formula with Select Case which identifies each transaction into a price range. I would then use this formula in my Crosstab. The main issue with this method is that there will be a large number of Cases & the possibility this will need to be added to / modified going forward.
Whilst I think this will work I am hoping there is better method to follow?
Thanks
JonHi Jamie,
Thank you for your help.
I'm looking to group in increments of 10 so it looks like the Floor function will do the trick, thank you.
I'll probably use an If statement to do a "block" of prices at either end of the scale (ie < 100 then 100, > 1000 then 1000+ else Floor ({Sales Field},10). Hopefully this way I'll reduce the overall no of rows.
Thanks again for your help.
Jon -
Deletion of Release Group and Code in PO
Dear Consultant,
In Purchase order, we have created some release group and code, Unfortunately we deleted some groups Without deleting in Order wise.
In table level the Release Group is there but in SPRO Release Strategy settings its not there..My consultant advised again you have to create same release group in Release strategy...
If I create same Release Group which are lying in my T16FC Table..But system throwing this err "An entry already exists with the same key"
Could you suggest me.
Regards,
PRIYA.Hi,
Please go with below mention path: -
SPRO >> Materials Management >> Purchase Order >> Release Procedure for Purchase Orders >> Define Release Procedure for Purchase Orders >> Release Groups.
Here check release group is existing, if yes then remove them and click on save button.
Then try to create new service group.
Some times we delete release group and create new release group with same description without saving changes.Due to this this type of error is occur.
Regards, -
How I check in group by query the group change
How I check in group by query the group change
Hi master
Sir I have master detail table
This is my query
select rownum,chartofacc.accid,title,nvl(drbal,0),nvl(crbal,0),
(select case when nvl(sum(debit),0)-nvl(sum(credit),0)>0 then
nvl(sum(debit),0)-nvl(sum(credit),0)
else
0
end mfadrttt
from voudetail where voudetail.accid=chartofacc.accid) as mfadr,
(select case when nvl(sum(credit),0)-nvl(sum(debit),0)>0 then
nvl(sum(credit),0)-nvl(sum(debit),0)
else
0
end mfacrttt
from voudetail where voudetail.accid=chartofacc.accid) as mfacr
,nvl(debit,0),nvl(credit,0),voumaster.entdate,voumaster.vno from chartofacc ,accbal,voudetail,voumaster where chartofacc.accid=accbal.accid(+) and chartofacc.accid=voudetail.accid(+) and voumaster.vno=voudetail.vno order by chartofacc.accid,voumaster.entdate,voudetail.VNO;
Sir I need add opbal from master section to debit in detail section when new group start only after adding I use that column for accumulative total or running balance
If I get any method when group change system give me any key or indication then I use
Please give me idea in both field oracle sql and oracle report 6i
Thank
aamirHi,
Please send tables structures and sample data from that tables. And, of course what should be the output. :) Just sending your query won't help us to find a solution.
Peter D. -
FBL1N with dynamic selection WITHHOLDING TAX CODE is dropping rows
Using FBL1N with dynamic selection field: WITHHOLDING TAX CODE and noticed that several vendors dropped off the report. Appears FBL1N's filter logic uses LFB1-QSSKZ and not LFBW-WT_WITHCD. Upon examination, I determined that the missing vendors didn't have a WTC assignment (column is BLANK) in table LFB1. Problem is I'm using transaction FK02's WITHHOLDING TAX ACCT tab to assign the WT codes but these rows are written to table LFBW (not LFB1). How is the LFB1-QSSKZ field populated? And why do some of the entries in LFB1-QSSKZ have values while others do not? Would ultimately like to populate the blank assignments with the correct WT code.
Hi Steve,
This is due to the limitation due to standard design.
You can see that a vendor can be assigned to multiple WHT codes and can also have multiple WHT code for a single line item. Hence in FBL1N output it would not be possible to show the WHT code as there is no one to one relationship.
You can click on the line item and can then see the WHT information in WHT button. Or alternatively get the data in withholding tax information reports.
Regards,
SDNer -
Assign SQ03 Abap Query User Group to role
Please advise how to assign SQ03 Abap Query User Group to a role. Thanks.
Moderator message: please do more research before asking.
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
[Asking Good Questions in the Forums to get Good Answers|/people/rob.burbank/blog/2010/05/12/asking-good-questions-in-the-forums-to-get-good-answers]
Edited by: Thomas Zloch on May 12, 2011 5:40 PMHello Sunil,
The problem is that I have hundreds of users to maintain user groups.
found out that it is possible to assign user group to role and role to user groups. implementing hr authorization with in-direct assignment of auth. So if I could use sq10, user groups could also be link to position in the org chart.
sq10 does allow you to assign a user group to a role but when you assign the role to a user and the user runs a query, it reports that no user group has been assigned.
Suspect that there must be a parameter or switch that is not turned on
Regards -
Can we replace this SELECT query by more efficient code
can we replace this SELECT query by more efficient code ?:-
SELECT * FROM zv7_custord
INTO TABLE G_T_ZV7_CUSTORD
WHERE ( SENDER in S_SENDER and
ORDNUM in S_ORDER and
ZDATE in S_DATE ) OR
( SENDER in S_SENDER AND
STATUS = SPACE )
ORDER BY IDOCNUM.Hi
U can leave ORDER BY option and sort the table by yourself and try to split the query:
SELECT * FROM zv7_custord
INTO TABLE G_T_ZV7_CUSTORD
WHERE SENDER in S_SENDER and
ORDNUM in S_ORDER and
ZDATE in S_DATE .
SELECT * FROM zv7_custord
APPENDING TABLE G_T_ZV7_CUSTORD
WHERE SENDER in S_SENDER and
NOT ORDNUM in S_ORDER and
NOT ZDATE in S_DATE and
STATUS = SPACE
or
SELECT * FROM zv7_custord
INTO TABLE G_T_ZV7_CUSTORD
WHERE SENDER in S_SENDER and
ORDNUM in S_ORDER and
ZDATE in S_DATE .
SELECT * FROM zv7_custord
APPENDING TABLE G_T_ZV7_CUSTORD
WHERE SENDER in S_SENDER and
STATUS = SPACE.
* Sort the table key fields
SORT G_T_ZV7_CUSTORD BY <KEY1> <KEY2> .....
DELETE ADJACENT DUPLICATES FROM G_T_ZV7_CUSTORD COMPARING <KEY1> .....
Max -
Catalogs, code groups and codes not available in service order in Web UI
Hi,
I have created and maintained a subject profile for the service orders that i am using for my business scenarios. The same is visible under the objects tab in transaction data of the service order business transaction in the SAP GUI.
However the same are not visible anywhere in the Web UI (they are not available in the list of available fields as well in BSP_WD_CMPWB for BT116H_SRVO).
Can some1 pls advice me with the steps so as to make the catalogs, code groups and codes in my service orders available in the Web UI screen as well.
Will really appreciate if detailed steps are provided since I am new to Web UI technology.
Warm regards,
DPDeepak,
I'm 99% sure (although dont quote me as I dont have a developer key so I cant finish my testing) that you're missing the context Nodes - so although you have the assignment block yuo have no link between the code set and the service order header. You havent referenced them in your comments on this post in any case.
Try this:
Go into BSP_WD_CMPWB
In the Browser component Structure open folder Component > Views
Double-click BT116H_SRVO/DetailsOV and in the structure expand to BT116H_SRVO/DetailsOV > BT116H_SRVO/DetailsOV > View Controller > DetailsOV.do > Context
Right-click on folder Context Node and click Create
Follow through the wizard defining a Z context Node (e.g. ZBTSubject) and a Model Node of BOL Entity BTSubject
Define any Dependencies etc you may wish to have and so on (most of the wizard is optional)
Repeat the same for the BOL Entity BTSubjectSet
Now go back in and see if your values are populating. I'm not a developer (and never have been), so I cant guarantee this will work as I dont have a developer key to test this, but I am quite sure that this needs to be done for you to get your values populating.
Good luck, Merry Christmas and a Happy New Year (& please award points if useful!)
Andrew Griffin. -
Quality Module Question: Grouping Defect Codes by Work Center
Is it possible to group Defect Codes by Work Center?
Welcome to the forum.
Please post this question in the below forum
[Forum: ERP Operations - Quality Management (QM)|SAP ERP Operations - Quality Management (SAP QM);
thanks
G. Lakshmipathi -
BEX Query to ABAP Transaction Code
Hi,
RRI from BEX Query to ABAP Transaction Code When I Right clivk and select GOTO on my Delivery order
say 120012 It shd directly go into tht particular DO The transaction code is vl33n
but when i give ABAP Transaction as reciever object it only goes to the initial screen of query where we manually need to give the DO Number It does not show the DO 120012 directly
thx,
amarHi Amar
Try doing Assigning Infoobject to R/3 field in Assignment details RSBBS transaction:
Check below thread for explaination
Re: RRI - Selection was not Restrcited
Ravi -
Hierarchical Tree Data Query/Record Group Question
I need help with Hierarchical Forms right now. I'm currently trying to implement a hierarchical tree to display the different items in different categories. I have been reading up on it for the past few days, and i do not understand a few things.
What is the difference between a data query and record group? they seem the same to me.
How does the XX = prior XXX work? i understand that this is what connects the parent to the child.
How do you determine what depth the node is? its done in the record group/data query, but how do i decide what level it is dynamically?
Thanks a lot in advance!Thanks! I am unable to create a table specifically for the tree because i am using tables that have been ported live and are in use. My question about levels is how do I know which depth the node is. For example, i have a category called Information Technology and a category item called Business Informatics. I want to know how to decide that the Category(information technology) is on level 1 and the Item(business informatics) is on level 2.
Information Technology
|_
Business Informatics
And i do know how the Connect By XX = prior XXX works in the data query/record group.
Thanks for your help! -
Grouping and UnGrouping of JTable Rows?
Hi,
Has somebody done Grouping and UnGrouping of JTable Rows as we find in MS-Excel.
Thanks & regards
blueHi,
Have anyone done something like this.
If u r not clear about the requirement:
Please see the screenshot uploaded at below url:
[http://www.geocities.com/coolneela/GroupableTable.JPG]
As shown the screenshot i want the Group 1 ,2,3 to be expandable and hideable i.e should behave like a Jtree node.....In rest of the column User can enter any input i.e for the columns A,B,C..
thanks & regards
Neel -
Empty query cache with ABAP code
Hi Experts,
Is there any way to empty the query cache using ABAP code?
Thank you!
Regards,
SamSam,
You can clear cache by using transaction RSRCACHE. Also, you can use a BDC ABAP program to do it.
-Saket
Maybe you are looking for
-
When using Mail Connection Doctor two error messages come up with regards to sending and receiving mail from my @mac.com account. The first one says that my @mac.com account: "Could not connect to this MobileMe IMAP server." How do I fix this? Is thi
-
OBIEE 11G - Max Time Parameter on the RPD IS NOT WORKING
Our OBIEE 11.1.1.7.1 cluster environment (2 nodes) has been setup on the repository to time out the queries if they run for more than 5 minutes. The requirement is if the query takes longer than 5 mins the query to the database should be cancelled on
-
How to view the open ports of a remote machine?
is ther anyway for java to view the open ports of a remote machine. i am developing a remote desktop sharing program...i remotely control a user's machine on LAN. so i sometimes need to launch a website,launch an application, or give a message to the
-
HT201257 Screen/ Display Problems- maybe hardware related?
Has anyone experienced a problem with their display- where an open window repeats over and over the entire screen (sometimes appearing like random squares) and the only way to correct the display seems to be by opening finder and dragging it across t
-
Spot lights at bottom of screen
MBP 4,1 2.6GHZ 15 inch (early 2008) OS X 10.10. I noticed at the bottom of the screen what looked like a row of evenly spaced spotlights shining upwards. After a restart they disappeared and the screen looks normal. Does anyone know what caused this,