Need query for below requirement
create table nsk_temp2 (num number,parent_num number,src_num number);
insert into nsk_temp2 values (1000,null,null);
insert into nsk_temp2 values (1001,1000,null);
insert into nsk_temp2 values (1002,1000,null);
insert into nsk_temp2 values (1010,null,1000);
insert into nsk_temp2 values (2001,1010,null);
insert into nsk_temp2 values (2002,1010,null);
num parent_num src_num
1000
1001 1000
1002 1000
1010 1000
2001 1010
2002 1010
Expected output
num parent_num src_num
1000
1001 1000
1002 1000
1010 1000
2001 1010 1001
2002 1010 1002
2001 -> parent is 1010 and 1010 src_num is 1000 and 1000 is parent for 1001 and 1002, so 1001 and 2001 are identical records
Hi,
This does what you requested:
WITH got_r_num AS
SELECT num, parent_num, src_num
, ROW_NUMBER () OVER ( PARTITION BY parent_num
ORDER BY num
) AS r_num
FROM nsk_temp2
SELECT d.num, d.parent_num
, NVL ( d.src_num
, s.num
) AS src_num
FROM got_r_num d
LEFT OUTER JOIN got_r_num m ON m.num = d.parent_num
LEFT OUTER JOIN got_r_num s ON s.parent_num = m.src_num
AND s.r_num = d.r_num
ORDER BY d.num
;Whether or not it gets the right results for the right reasons, I can't say, since I know so little about the reasons.
If 1001 and 2001 are identical, aren 1001 and 2002 identical, too? Can the parent_num/num hierarchy extend beyond 2 levels? What would happen if 1000 had more, or fewer, children than 2000?
Similar Messages
-
How to write query for below requirement
Hi sir,
i have a table x have one column y which containing value like below
Y
a
b
c
d
I want out put like below kindly help me:
Y
a
d
c
bHi ,
Please check:
select y from (
select case when y='a' then 1 else 2 end no, y from table_x
) order by no asc, y desc
with table_x as(
select 'a' y
from dual
union
select 'b' y
from dual
union
select 'c' y
from dual
union
select 'd' y
from dual
select y from (
select case when y='a' then 1 else 2 end no, y from table_x
) order by no asc, y desc
Thank you -
How to write select query for below requirement
Hi sir,
i have a table x have one column y which containing value like below
Y
a
b
c
d
I want out put like below kindly help me:
Y
a
d
c
bHi ,
Please check:
select y from (
select case when y='a' then 1 else 2 end no, y from table_x
) order by no asc, y desc
with table_x as(
select 'a' y
from dual
union
select 'b' y
from dual
union
select 'c' y
from dual
union
select 'd' y
from dual
select y from (
select case when y='a' then 1 else 2 end no, y from table_x
) order by no asc, y desc
Thank you -
How to write sql query for below example.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD
MANAGER 5 NULL null
SR.MANAGE 6 3 NULL
VP 5 5 4
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD
5(MANGER) 3(sr.manger) 5(vp)
Please provide the for above mentioned output.
Thanks<<if COLA IS MANAGER THEN CONSIDER MANGER RECORD>>
What does this sentence means? COLA does not cnatin a single record but the number of records with diffrent values.
Regards
Arun -
How to write sql query for below mentioned eaxmple.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD COLE COLF MANAGER 5 NULL NULL 3 NULL
SR.MANAGER 6 3 NULL NULL NULL
VP 5 5 4 5 5
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD COLE COLF
5(manager) 3(sr.manger) 4(vp) 3(manger) 3(vp)
Please provide the for above mentioned output.
ThanksDuplicate thread. please view the answer posted in your first thread.
how to write sql query.
And, please don't post any duplicate thread.
Regards.
Satyaki De. -
Need help for my requirement...
Need help for my requirement...
Hello Experts,
I have report where users can input the company, housebank, account ID and posting date.
Now in one column of my report named 'Cash in Bank', I need to get all postings from cash
accounts with GL code ending in '0'. Now, I know that I can get the amounts in BSIS/BSAS
but how do I link it with the proper bank and account?
For example:
Cash in Bank
Bank A
Account ID 1 1,000,000
Account ID 2 25,000,000
Hope you can help me guys. Thank you and take care!hi Viraylab,
each house bank you can find in table T012, in T012K you'll find the bank accounts to the housebank, the G/L account will be in T012K-HKONT.
hope this helps
ec -
Need Query for empty partitions
I am having nearly 700 partitions for a table.Now i want to find out only the empty partitions.I need query for that.
Thankx..Not the most elegant solution, but it works:
declare
rc number;
str varchar2(200);
begin
for i in (select table_owner, table_name, partition_name from dba_tab_partitions) loop
str := 'select count(*) from ' || i.table_owner || '.' || i.table_name || ' partition (' || i.partition_name || ')';
execute immediate str into rc;
if rc = 0 then
dbms_output.put_line(i.table_owner || '.' || i.table_name);
end if;
end loop;
end; -
Provide sql query for below one
hi everyone,
in my source table [finanace_dept] contains two columns [finance_id,r_mature_kd] with 2 million records and sample data given below.
finance_id r_mature_kd
1 H
1 T
1 T
2 T
3 H
4 S
4 T
4 T
5 X
6 H
6 L
6 L
6 M
please provide sql query for below expected output.
expected output :
finance_id r_mature_kd
1 H
1 T
4 S
4 T
6 H
6 L
6 M
for column finance_id: '1', contains three records, but two distinct r_mature_kd hence it should retrive only two records with H,T
for column finance_id: '2','3', contains only one record hence this records should not retrive.
for column finance_id: '6', contains four records, but three distinct r_mature_kd hence it should retrive only two records with H,L,M
please help on this.WITH T(finance_id,r_mature_kd) AS (
SELECT 1, 'H' FROM DUAL UNION ALL
SELECT 1, 'T' FROM DUAL UNION ALL
SELECT 1, 'T' FROM DUAL UNION ALL
SELECT 2, 'T' FROM DUAL UNION ALL
SELECT 3, 'H' FROM DUAL UNION ALL
SELECT 4, 'S' FROM DUAL UNION ALL
SELECT 4, 'T' FROM DUAL UNION ALL
SELECT 4, 'T' FROM DUAL UNION ALL
SELECT 5, 'X' FROM DUAL UNION ALL
SELECT 6, 'H' FROM DUAL UNION ALL
SELECT 6, 'L' FROM DUAL UNION ALL
SELECT 6, 'L' FROM DUAL UNION ALL
SELECT 6, 'M' FROM DUAL
SELECT DISTINCT finance_id,r_mature_kd,C FROM(
SELECT finance_id,r_mature_kd,COUNT(1) OVER (PARTITION BY finance_id) C
FROM T
WHERE C > 1
ORDER BY 1
FINANCE_ID
R_MATURE_KD
C
1
H
3
1
T
3
4
S
3
4
T
3
6
H
4
6
L
4
6
M
4
Ramin Hashimzade -
Need solution for below requiernment
Hi,
Please tell me flow logic for below requiernment:
1. Read actual payroll period from T569V for ABKRS set in infotype 0001
2. Read actual payroll result from cluster RD using german standard functions
3. Loop through table RT and check for wagetype 9000
4. create a batch-input to infotype 0015 wagetype 9000
ANZHL = 1
ZEINH = piece
BEGDA = actual month - 1 (e.g. actual month 06/2008 enter 01.05.2008)
5. allow option for direct or delayed start of batchinput
My confusion is: 1) Why do we need to Read actual payroll period from T569V for ABKRS set in infotype 0001.
2) To update IT 0015 , do we need to write a BDC or we can use FM HR_INFOTYPE_OPERATIONS.
regardshi,
1.this requirement may be cause of mid year go live in the past.
2. BDC for IT 15 makes sense as it is easier to maintain a BDC program.
Regards
Sameer. -
How to place nulls has last rows.Find query for below problem
I have a table..MyTable(value number(10))
select * from Mytable;
value
12
null
13
null
11
null
This is the table i have and the records i have...... and i need output like this
value
12
13
11
null
null
null ..............>ike this i need output for this i use this query i.e
Query-->select value from mytable where value is not null
union all
select value from mytable where value is null
------------>and this query gives only one column result i need multiple results like below: i have table with 2 columns like below
MyTable2(value1 number(10),value2 number(10))
select * fromMyTable2
value1 value2
111 null
null 201
112 null
null 200
110 null
this is the table i have......... and i need output like below
value1 value2
111 201
112 200
110 null
null null
null null
NOTE:: If we use ORDER BY table records order must change, i don't want to change any order....please what is the query for thatI'm not able to find any sense in your request but it can be done:
select value1, value2
from (select value1, rownum rn from
(select value1 from mytable where value1 is not null
union all
select value1 from mytable where value1 is null)
) a,
(select value2, rownum rn from
(select value2 from mytable where value2 is not null
union all
select value2 from mytable where value2 is null)
) b
where a.rn = b.rn;You should study some book about relational databases to understand frst of all what a record is, and then that records in a table are not ordered.
Max -
How to form a query for this requirment
Hi Friends,
I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
Can any one please post SQL query for this scenario ?
Thanks in AdavanceI cannot imagine, that second and third query are
under any circumstances faster as first one, but i
can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
A quick check on those two selects
SELECT object_id, object_type, object_name
FROM user_objects;
SELECT object_id, object_type, object_name
FROM (SELECT object_id, object_type, object_name
FROM user_objects)
;didn't show any changes in the explain plan unter 10g1.
C. -
Need T-SQL query for Below condition, Thanks!
experts,
i having a table with below data,
declare @tbl table (uid int, name varchar(10), id int)
insert table @tbl values (1, 'val1', 6)
insert table @tbl values (2, 'val2', 6)
insert table @tbl values (3, 'val2', 8)
insert table @tbl values (4, 'val1', 8)
insert table @tbl values (5, 'val2', 7)
insert table @tbl values (6, 'val1', 10)
need to get all rows for those "id"'s which having both "name" ("val1" & "val2")?
below should be output, thanks!@
declare @tbl table (uid int, name varchar(10), id int)
insert table @tbl values (1, 'val1', 6)
insert table @tbl values (2, 'val2', 6)
insert table @tbl values (3, 'val2', 8)
insert table @tbl values (4, 'val1', 8)here you go with full illustration
declare @tbl table (uid int, name varchar(10), id int)
insert @tbl values (1, 'val1', 6)
insert @tbl values (2, 'val2', 6)
insert @tbl values (3, 'val2', 8)
insert @tbl values (3, 'val10', 8)
insert @tbl values (4, 'val1', 8)
insert @tbl values (5, 'val2', 7)
insert @tbl values (6, 'val1', 10)
insert @tbl values (6, 'val24', 11)
SELECT *
FROM @tbl t
WHERE EXISTS
SELECT 1
FROM @tbl
WHERE id = t.id
GROUP BY id
HAVING COUNT(DISTINCT CASE WHEN name IN ('val1','val2') THEN name END) = 2
and name IN ('val1','val2')
output
uid name id
1 val1 6
2 val2 6
3 val2 8
4 val1 8
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Report Builder Version:10g
Hi Guys Good Morning to one and all
I have a table Named Onlsuvdet which captures the answers from
an online survey front end which has multiple choice questions.
the table structure is as follows
create table onlsuvdet(shloid number,questno char(5),respo1 char(5),respo2 char(5));
and the sample data is as follows
SHLOID QUEST RESPO RESPO
9315 1 2
9315 2 3
9315 3 4
9315 3 5
9315 4 1
9315 5 2
9315 5 1
Now i want the result as follows
shlogid quest1 quest2 q3 q4 q5
9315 2 3 4,5 1 2,1
So my requirement is a query which displays this data as above.
Please helpppp
Any help will be appreciated :)
Thanks & RegardsHi,
user123 wrote:
Report Builder Version:10g
Hi Guys Good Morning to one and all
I have a table Named Onlsuvdet which captures the answers from
an online survey front end which has multiple choice questions.
the table structure is as follows
create table onlsuvdet(shloid number,questno char(5),respo1 char(5),respo2 char(5));Thanks for posting the CREATE TABLE statement. That helps.
Why are you using the CHAR datatype, rather than VARCHAR2? CHAR is nothing but trouble.
and the sample data is as follows
SHLOID QUEST RESPO RESPO
9315 1 2
9315 2 3
9315 3 4
9315 3 5
9315 4 1
9315 5 2
9315 5 1Always post your data in a form people can use to re-create the problem and test their solutions. for example:
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '1 ', '2 ', NULL);
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '2 ', '3 ', NULL);
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '3 ', '4 ', NULL);
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '3 ', NULL, '5 ');
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '4 ', '1 ', NULL);
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '5 ', '2 ', NULL);
INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '5 ', NULL, '1 ');I'm making a lot of guesses about the data. for example, I'm guessing there will never be more than 2 rows with the same shloid and questno.
Why do you have 2 columns, respo1 and respo2? Is exactlyly one of them always NULL? If respo1 is NULL, will there always be another row with the same shloid and questno, but with a NULL respo2?
Now i want the result as follows
shlogid quest1 quest2 q3 q4 q5
9315 2 3 4,5 1 2,1Be consistent with the column names; either call them all questn (like I did below) or call them all qn.
So my requirement is a query which displays this data as above.Perhaps something like this:
WITH joined_data AS
SELECT r1.shloid
, r1.questno
, RTRIM ( r1.respo1 || ',' || r2.respo2
) AS respo
FROM onlsuvdet r1
LEFT OUTER JOIN onlsuvdet r2 ON r1.shloid = r2.shloid
AND r1.questno = r2.questno
AND r1.respo1 IS NOT NULL
AND r2.respo2 IS NOT NULL
SELECT shloid
, MAX (CASE WHEN questno = '1 ' THEN respo END) AS quest1
, MAX (CASE WHEN questno = '2 ' THEN respo END) AS quest2
, MAX (CASE WHEN questno = '3 ' THEN respo END) AS quest3
, MAX (CASE WHEN questno = '4 ' THEN respo END) AS quest4
, MAX (CASE WHEN questno = '5 ' THEN respo END) AS quest5
FROM joined_data
GROUP BY shloid
I hope this answers your question.
If not, point out a few places where the query above gets the wrong results. Post the correct results (formatted, between \ tags, as explained in the FAQ
http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ
) and explain how you get the correct results from the given data. Correct or add to the sample data that I psoted, if necessary. -
Need input for this requirement?
Hi All,
I got new requirement. In this i need to display one world map on that map i have so show blinking star for the customer countries.
if the user click on perticular blinking star i need to display some data.
How to achive this? please help me out.
Thanks and Regards,
Phani Kumar.Phani,
You can also use Google Maps API .You can find help in below links:
http://code.google.com/apis/maps/documentation/reference.html
http://net.tutsplus.com/javascript-ajax/this-is-how-you-use-the-google-maps-api/
-Suresh -
Need Query for Item Relationship of Oracle Apps
Hello Team,
I need the Query to select the Item Relationship.
In Oracle Apps we have different tyes of Structure
ItemA -> ItemB
ItemB -> ItemC
ItemC -> ItemD
ItemG -> ItemH
ItemK -> ItemL
ItemW -> ItemQ
and this also is possible (meand many to one relationship)
ItemA -> ItemB
ItemB -> ItemC
ItemC -> ItemD
ItemT -> ItemD
and in the Select Query i want the below result
ItemA -> ItemB 1
ItemB -> ItemC 2
ItemC -> ItemD 3
ItemG -> ItemH 1
ItemK -> ItemL 2
ItemW -> ItemQ 1
and this also is possible (means many to one relationship)
ItemA -> ItemB 1
ItemB -> ItemC 2
ItemC -> ItemD 3
ItemT -> ItemD 1
means i want the Hierarchy number also
Please help me to in order to get the relationship by sql query.
Kind Regards,thanks for the quick response and i would love to spend time perusing the forum for this question but i didn't have time today. i'll do that now though.
what i'm mostly interested in is a chronological view (lastUpdateDate) of the change to pricing for an item in the system. there is a lot of activity in our system around price changes for promotions and i want to keep track of when it's changed in the source system and pair that with our other downstream systems.
i'm assuming we can add this functionality through a udf some way or maybe sp_TransNotification proc?
Maybe you are looking for
-
Need to restrict selection screen entries in logical database in HR report
After creating custom HR Report Category using Logical database, I need to restrict the options available in the in the selection Screen for example- for company code i m getting 182 entries, but after running the program, selection-options for compa
-
"Open Picture Window Fever" not working properly
I've used "Open Picture Window Fever" successfully until recently. After adding the behavior, and viewing my page in a browser, the images do not open using "Fever." When I check the behavior specs to make sure the dimensions are there, "image name,
-
Ipod classic no sound from headphones
My Ipod classic has no sound from the headphones?
-
Basically, why can't use my iSight as a Twain resource in PhotoShop or Image Capture?
-
Hi how to do for enter in my account apple
how to do for enter in my apple account and verficated it