Finding the highest parent...
Hi Guys,
I have two tables.
First table is tblTeam:
Team_ID ~ Team_Name
1 ~ Overall Accounting Group
2 ~ Accounting - USA
3 ~ Accounting - Europe
4 ~ Accounting - Texas
5 ~ Accounting - NYC
6 ~ Accounting - London
7 ~ Accounting - Dublin
The second table is the relationship table, tblTeamRel. It has 2 one to many relationships with tblTeam, a parent and a child relationship:
Parent_Team_ID ~ Child_Team_ID
1 ~ 2
1 ~ 3
2 ~ 4
2 ~ 5
3 ~ 6
3 ~ 7
I want to write a query where you give the a team_ID and you get its highest team_ID back, for example:
I enter team_ID 7 (Accounting - Dublin) and it returns team_id 1 (Overall Accounting Group)
or I enter team_ID 2 (Accounting - USA) and it returns team_id 1 (Overall Accounting Group)
Im not sure where to start with this query so any examples you can show me or any help you can give me would be greatly appreciated...
Thanks,
Sean
Edited by: Hazy on May 14, 2010 1:35 PM
Maybe something like this?
SQL> var childTeam NUMBER;
SQL>
SQL> exec :childTeam := 7;
PL/SQL procedure successfully completed.
SQL> WITH tblTeam AS
2 (
3 SELECT 1 AS TEAM_ID, 'Overall Accounting Group' AS TEAM_NAME FROM DUAL UNION ALL
4 SELECT 2 AS TEAM_ID, 'Accounting - USA' AS TEAM_NAME FROM DUAL UNION ALL
5 SELECT 3 AS TEAM_ID, 'Accounting - Europe' AS TEAM_NAME FROM DUAL UNION ALL
6 SELECT 4 AS TEAM_ID, 'Accounting - Texas' AS TEAM_NAME FROM DUAL UNION ALL
7 SELECT 5 AS TEAM_ID, 'Accounting - NYC' AS TEAM_NAME FROM DUAL UNION ALL
8 SELECT 6 AS TEAM_ID, 'Accounting - London' AS TEAM_NAME FROM DUAL UNION ALL
9 SELECT 7 AS TEAM_ID, 'Accounting - Dublin' AS TEAM_NAME FROM DUAL
10 ), tblTeamRel AS
11 (
12 SELECT 1 AS PARENT_TEAM_ID, 2 AS LD_PARENT_ID FROM DUAL UNION ALL
13 SELECT 1 AS PARENT_TEAM_ID, 3 AS LD_PARENT_ID FROM DUAL UNION ALL
14 SELECT 2 AS PARENT_TEAM_ID, 4 AS LD_PARENT_ID FROM DUAL UNION ALL
15 SELECT 2 AS PARENT_TEAM_ID, 5 AS LD_PARENT_ID FROM DUAL UNION ALL
16 SELECT 3 AS PARENT_TEAM_ID, 6 AS LD_PARENT_ID FROM DUAL UNION ALL
17 SELECT 3 AS PARENT_TEAM_ID, 7 AS LD_PARENT_ID FROM DUAL
18 )
19 /* END SAMPLE DATA */
20 SELECT parent_team_id
21 , team_name
22 FROM tblTeam
23 JOIN tblTeamRel ON tblTeam.team_id = tblTeamRel.parent_team_id
24 WHERE CONNECT_BY_ISLEAF = 1
25 START WITH ld_parent_id = :childTeam
26 CONNECT BY PRIOR parent_team_id = ld_parent_id
27 /
PARENT_TEAM_ID TEAM_NAME
1 Overall Accounting Group
SQL> exec :childTeam := 2;
PL/SQL procedure successfully completed.
SQL> /
PARENT_TEAM_ID TEAM_NAME
1 Overall Accounting GroupIn the future you'd probably get a faster response in the {forum:id=75} forum.
Additionally, it's always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
You provided #3 and #4. You kind of provided #2 but not in a usable form.
Edited by: Centinul on May 14, 2010 1:23 PM
Similar Messages
-
How to use my findTheHighest method to find the highest value in my two dim
I am going to create a 13row by 10 colume two dimensional array.
how to use my findTheHighest method to find the highest value in my two dimensional array.
.When i compile this program , i got those as following;
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
at TaxEvolution.findTheHighest(TaxEvolution.java:31)
at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
public class TaxEvolution{
public double[][] salesTaxRates;
public TaxEvolution()
salesTaxRates = new double[13][10];
fillProvinTaxRates();
private void fillProvinTaxRates()
for ( int row = 0; row < salesTaxRates.length; row++ )
for ( int column = 0; column < salesTaxRates[row].length; column++ )
salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
public double findTheHighest()
double highest = salesTaxRates[0][0];
for ( int row = 0; row <= salesTaxRates.length; row++ )
for ( int column = 0; column <= salesTaxRates[row].length; column++ )
if ( salesTaxRates[row][column] >= highest )
highest = salesTaxRates[row][column];
return highest;
public double[][] arrayTaxEvolution()
double[][] returnTaxRates = new double[13][10];
for ( int row = 0; row < salesTaxRates.length; row++ )
for ( int column = 0; column < salesTaxRates[row].length; column++ )
returnTaxRates = salesTaxRates;
return returnTaxRates;
public class TaxEvolutionClient{
public static void main( String[] args ){
TaxEvolution protaxRateList = new TaxEvolution();
double[][] taxRateList = protaxRateList.arrayTaxEvolution();
for ( int i = 0; i < taxRateList.length; i++ )
for ( int j = 0; j < taxRateList[0].length; j++ )
System.out.print( taxRateList[i][j] + "\t" );
System.out.print( protaxRateList.findTheHighest + "\t" );
}Multiposted
http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0 -
How to Find the highest and lowest cell in a column and figure the difference
What I am tryng to do is have numbers find the high and low in Cloumn B and and put the difference in B6. So I would need it to Figure out that B3 is the highest and B2 is the lowest and give me the difference of .25 in B6
Don,
Begin by making Row 6 a Footer Row. You will find that option in the row tab menu that appears when you hover over the 6 tab and click the triangle.
Then enter this formula in B6:
=MAX(B)-MIN(B)
Regards,
Jerry -
Trying to find the highest possible MTU
Hello,
I try to find out, wich is the highest possible MTU. So I send a PING -L XXXX -F to the Pix outside, from outside. XXXX is standing for the bytes.
PING xxx.xxx.xxx.xxx -L 992 (and lower) -F
I got a reply
PING xxx.xxx.xxx.xxx -L 993 (up to1472) -F
the ping timed out
PING xxx.xxx.xxx.xxx -L 1473 (and higher) -F
Fragmentation is needed
I don't understand, why it timed out between 993 an 1472.
If i try the same to a router (same internet connection), the ping works up to 1472, with no time out. Upeer 1472 I get the fragmentation message.
Have enyone an answer?
ThomasMy problem occurs also without any encryption. I'm connected to the internet and send a ping to the outside interface of the PIX. First a thought it is a problem with the router from the ISP, but we have also a CISCO 1605 connected to the same ISP router and there the ping work realy fine until 1472 bytes the I get the message fragmentition needed.
If I'm connected via the VPN Client 3.51 and send a ping to inside, I get the same results, but additional on the PIX, if debug ipsec is on, a message like this: IPSEC(ipsec_cipher_handler): ERR: bad pkt 10.1.80.3->10.1.1.1
I searched in the errordecoder from Cisco, but there are no results.
By the way, the pre-fragmentation is by default on and I didn't switch it off. It occurs not in IPSEC transfermode, which I'm using. -
Finding the highest flow period for a day
Now I really got stuck. I need to find what period for a day (full 24h) that have the highest flow. To make things a bit harder we cant used fixed periods. We have the flow per minute to work with.
Example with 10 minutes and we look for a 5 minute period:
Time ; Flow
0700 ; 14
0701 ; 12
0702 ; 18
0703 ; 19
0704 ; 12
0705 ; 16
0706 ; 10
0707 ; 10
0708 ; 15
0709 ; 14
In this case the highest flow for the period would be between 0701 and 0705 with a total flow of 77. So the needed answer would be 0701 and 77
In the situation where it will used in reality it will be finding a 15 minute period from 1440 minutes we have for a day.
I hope someone can provide me with ideas of how to solve this thing.
Regards,
JonasAre you guaranteed to have a row for every minute?
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
JServer Release 9.2.0.6.0 - Production
SQL> DROP TABLE t;
Table dropped.
SQL> CREATE TABLE t (time VARCHAR2 (4), flow NUMBER);
Table created.
SQL> INSERT INTO t VALUES ('0700', 14);
1 row created.
SQL> INSERT INTO t VALUES ('0701', 12);
1 row created.
SQL> INSERT INTO t VALUES ('0702', 18);
1 row created.
SQL> INSERT INTO t VALUES ('0703', 19);
1 row created.
SQL> INSERT INTO t VALUES ('0704', 12);
1 row created.
SQL> INSERT INTO t VALUES ('0705', 16);
1 row created.
SQL> INSERT INTO t VALUES ('0706', 10);
1 row created.
SQL> INSERT INTO t VALUES ('0707', 10);
1 row created.
SQL> INSERT INTO t VALUES ('0708', 15);
1 row created.
SQL> INSERT INTO t VALUES ('0709', 14);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT time, flow
2 FROM (SELECT time, flow,
3 RANK () OVER (
4 ORDER BY flow DESC) flow_rank
5 FROM (SELECT TO_CHAR (time, 'HH24MI') time,
6 SUM (flow) OVER (ORDER BY time
7 ROWS BETWEEN CURRENT ROW AND 4 FOLLOWING) flow
8 FROM (SELECT TO_DATE (time, 'HH24MI') time, flow
9 FROM t)))
10 WHERE flow_rank = 1;
TIME FLOW
0701 77
SQL> -
Find the grand parent of child node
Hi gurus,
I have a table with the following structure
Supp_Num Parent_Num Inidicator
1 Null 0
2 1 1
3 2 1
4 Null 0
5 4 1
For all the parent Nodes the indicator will have '0'
For all the child Nodes the indicator will have '1'.
I want to write a sQL code where i provide a child name and it traces back to its root parent . For eg if i provide the procedure with Supp_Num=3 it should traverse back to 1 and give 1 as output
Thanks in advance9ba2a86d-5f7e-4e53-99ee-d675435c2efd wrote:
Thanks for the reply but i'm expecting Supp_Num =4 as well since its parent for Supp_num=5 . Also i want to write it in a Stored Proc form where i just provide the
Supp_num as input and i get the root parent node as output.
Thanks in advance
You wrote in your original post
I want to write a sQL code where i provide a child name and it traces back to its root parent . For eg if i provide the procedure with Supp_Num=3 it should traverse back to 1 and give 1 as output
And my solution did exactly the same. Now if you want the Root details for SUPP_NUM=5, it will provide the root node for same. See below:
with data as
select 1 supp_num, null par_num, 0 ind from dual union all
select 2 supp_num, 1 par_num, 1 ind from dual union all
select 3 supp_num, 2 par_num, 1 ind from dual union all
select 4 supp_num, null par_num, 0 ind from dual union all
select 5 supp_num, 4 par_num, 1 ind from dual
select *
from (
select supp_num, par_num, ind
from data
start with supp_num = 5
connect by supp_num = prior par_num
where par_num is null;
SUPP_NUM PAR_NUM IND
4 0
You just need to set the START WITH clause with appropriate SUPP_NUM. -
Help to find the max, min and the averages wages
ok i did sum programming i got half of my program to work but i need help with the other half the program is suppose to find the highest and lowest wages and also give the average wages. here is my code
import java.util.*;
public class WorkerwagesQueues
static Scanner console = new Scanner(System.in);
public static void main (String[] args)
Queue<String> nameQ = new LinkedList<String>();
Queue<String> nameQ2 = new LinkedList<String>();
Queue<Double> num = new LinkedList<Double>();
int searchCnt = 0;
int max, min;
String toSearch, var;
System.out.println("Welcome, how are you Doing today\n");
System.out.println("Please enter the five workers names\n");
for (int i = 0; i < 5; i++)
nameQ.offer(console.next());
System.out.println("Please enter the five workers salaries\n");
for (int i = 0; i < 5; i++)
num.offer(console.nextDouble());
// starting right here is my problem
/*min = num.next(0);
max = num.get(0);
for (int i = 0; i < num.size(); i++)
System.out.println(num.get(i));
if (i > 0)
if (min > num.get(i))
min = num.get(i);
if (max < num.get(i))
max = num.get(i);
System.out.println("\nthe Lowest wage is " + num );
System.out.println("\nthe Largest wage is " + num );
System.out.println("please enter a name to serach the queue:");
toSearch = console.next();
while (nameQ.size() > 0)
var = nameQ.remove();
if (var.equals(toSearch))
{searchCnt++;}
else
{nameQ2.offer(var);}
System.out.println("This queue contains " + toSearch + " " + searchCnt + " time(s).");
System.out.println("The second queue is:");
}ok sorry if i am annoying you guys but i really want to get this working
this is the part i am having problems with. I am trying to find the max and min of the wages the user input and i am not usre how to do it. my question is how do i do that?
// starting right here is my problem
/*min = num.next(0);
max = num.get(0);
for (int i = 0; i < num.size(); i++)
System.out.println(num.get(i));
if (i > 0)
if (min > num.get(i))
min = num.get(i);
if (max < num.get(i))
max = num.get(i);
System.out.println("\nthe Lowest wage is " + num );
System.out.println("\nthe Largest wage is " + num );
-
Checking for the highest number
Hello, i am still doing tutorials in my book :d and i am stuck,
i am trying to find the highest number in an array, and this is my attempt so far
public void busiestHour()
for (int index = 0; index < hourCounts.length; index++){
if (hourCounts[index] > hourCounts[index - 1]){
int busiestHour = hourCounts[index];
}what i am doing is checking (in the if statement line) if the number in the array location (point index) is bigger than the array location at index -1 (the previous one)
i think the problem is, when it compares at the beginning there wont be anything at -1 will there :o lol so i dont no how to go about changing it
thanks very muchcompSciUndergrad wrote:
i was just trying to experiment to see which was easier :D
i have imported java.util.collections
but i am sure for it to work i would need something like this
int busiestHour = myArray.max(something in here?)Use a list (eg. ArrayList) instead of the array
List<Integer> hourCounts = new ArrayList<Integer>();
hourCounts.add(5);
int busiestHour = Collections.max(hourCounts);As I said: read the tutorials (or your book)
-Puce
Edited by: Puce on Nov 14, 2008 2:33 PM
Arrays.asList does not work with arrays of primitives, if I remember correctly. -
Dear friends,
I provide full details here ,my database table structure ,data and stored procedure and my problem ,
please review it and provide the solution or any idea to solve my problem.
I am working on a project in which members are added in a tree pattern, and get the payment accordingly.
below is my table structure ,data and stored procedure
CREATE TABLE Associate_Income
ID varchar(30) NOT NULL,
ParentID varchar(30) NULL,
IsLeft tinyint NULL,
IsRight tinyint NULL,
joingdate datetime NOT NULL
go
INSERT Associate_Income
(ID, ParentID, IsLeft, IsRight, joingdate)
SELECT 'Ramesh123', NULL, NULL, NULL '2014-01-03 16:31:15.000' UNION ALL
SELECT 'Sonu', 'Ramesh123', 1, NULL, '2014-01-03 16:45:21.000' UNION ALL
SELECT 'Pawan kumar', 'Ramesh123', NULL, 1, '2014-01-04 16:50:23.000' UNION ALL
SELECT 'Ravi123', 'Sonu', 1, NULL, '2014-01-04 17:03:22.000' UNION ALL
SELECT 'Vineet123', 'Sonu', NULL, 1, '2014-01-04 17:26:01.000' UNION ALL
SELECT 'dev123', 'Ravi123', 1, NULL, '2014-01-05 19:35:16.000' UNION ALL
SELECT 'Mukesh123', 'Ravi123', NULL, 1, '2014-01-05 19:40:41.000' UNION ALL
SELECT 'poonam123', 'Vineet123', 1, NULL, '2014-01-05 19:49:49.000' UNION ALL
SELECT 'monu', 'Pawan kumar', 1, NULL, '2014-01-05 17:32:58.000' UNION ALL
SELECT 'Arti123', 'Pawan kumar', NULL, 1, '2014-01-05 19:54:35.000' UNION ALL
My database table Associate_Income structure and data is as follow:
ID ParentID IsLeft IsRight joingdate
Ramesh123 NULL NULL NULL 2014-01-03 16:31:15.000
Sonu Ramesh123 1 NULL 2014-01-03 16:45:21.000
Pawan kumar Ramesh123 NULL 1 2014-01-04 16:50:23.000
Ravi123 Sonu 1 NULL 2014-01-04 17:03:22.000
Vineet123 Sonu NULL 1 2014-01-04 17:26:01.000
dev123 Ravi123 1 NULL 2014-01-05 19:35:16.000
Mukesh123 Ravi123 NULL 1 2014-01-05 19:40:41.000
poonam123 Vineet123 1 NULL 2014-01-05 19:49:49.000
monu Pawan kumar 1 NULL 2014-01-05 17:32:58.000
Arti123 Pawan kumar NULL 1 2014-01-05 19:54:35.000
by using below stored procedure i can count the total number of pairs under particular node in 2:1,1:1 ratio means first pair is completed when two node added to the left side of given parent node and one node added
right side of given parent node after that all pairs are completed when one node added left side and one node added right side of parent node (1:1 ratio)
example if i execute my stored procedure as follows it would return following.
EXEC count_pairs 'Ramesh123'
3
so there is 3 pairs as shown in my figure.
when we execute my stored procedure for ParentID 'sonu' it would return following.
EXEC count_pairs 'sonu'
2
so there is 2 pairs as shown in my figure.
My problem is to find the query which can return the total number of pair under particular node any given parent node. day to
day maximum 5 pairs in a day please any one can suggest us
CREATE proc [dbo].[count_pairs]
@ParentID nvarchar(50)
as
begin
Declare @ParentSUM SMALLINT = 0
Declare @SubLeftID nvarchar(50)
Declare @SubRightID nvarchar(50)
SELECT @SubLeftID = CASE WHEN [IsLeft] = 1 THEN [ID] ELSE @SubLeftID END
,@SubRightID = CASE WHEN [IsRight] = 1 THEN [ID] ELSE @SubRightID END
FROM Associate_Income
WHERE ParentID = @ParentID
IF @SubLeftID IS NOT NULL AND @SubRightID IS NOT NULL AND EXISTS(SELECT 1 FROM Associate_Income WHERE [IsLeft] = 1 AND ParentID = @SubLeftID)
BEGIN
SET @ParentSUM = 1
;WITH Associate_Income_CTE AS
SELECT [ID], [ParentID], [IsLeft], [IsRight], 0 AS [Level]
FROM Associate_Income
WHERE [ParentID] = @ParentID
UNION ALL
SELECT RecursiveMember.[ID], RecursiveMember.[ParentID], RecursiveMember.[IsLeft], RecursiveMember.[IsRight], Level + 1
FROM Associate_Income RecursiveMember
INNER JOIN Associate_Income_CTE AnchorMember
ON RecursiveMember.[ParentID] = AnchorMember.[ID]
SELECT @ParentSUM = @ParentSUM + COUNT([ParentID])
FROM
SELECT [ParentID]
,'IsLeft' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsLeft] = 1
AND [ID] <> @ParentID --AND [ID] NOT IN (@SubLeftID, @ParentID)
AND [ParentID] NOT IN (@ParentID, @SubLeftID)
UNION ALL
SELECT [ParentID]
,'IsRight' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsRight] = 1
AND [ParentID] <> @ParentID
) AS Associate_Income
PIVOT
MAX([Value]) FOR [Direction] IN ([IsLeft], [IsRight])
) PVT
WHERE [IsLeft] IS NOT NULL AND [IsRight] IS NOT NULL
END
SELECT @ParentSUM
Jitendra Kumar Sr. Software Developer at Ruvixo Technologies 7895253402I don't think this is homework, I am not sure how helpful it was by Kalman to merge the two threads. It appears that two different persons posted the questions. It could be though, that it is the same problem and Jitendra has taken over Chandra's
task.
However, I was not able to understand the problem nor the figure. And nor the definition of pairs in this context. My assumption is that what Jitendra posted is an abstraction of the actual problem in order to not reveal intellecutal property. Possibly this
makes the problem more difficult to understand for us outsiders.
I've come so far that I worked out a table definition and INSERT statements with sample data, as well as a call to the procedure which returns 3 and this appears to map to the figure, but I don't know what it means. Since I don't know what this
is about, I have not made any attepmts to understand the code, but I would appreciate clarification about the underlying business rules as well as the expected results for various test cases.
CREATE TABLE Associate_Income(ID varchar(30) NOT NULL,
ParentID varchar(30) NULL,
IsLeft tinyint NULL,
IsRight tinyint NULL,
joingdate datetime NOT NULL)
go
INSERT Associate_Income (ID, ParentID, IsLeft, IsRight, joingdate)
SELECT 'Ramesh123', NULL, NULL, NULL, '2014-01-03 16:31:15.000' UNION ALL
SELECT 'Sonu', 'Ramesh123', 1, NULL, '2014-01-03 16:45:21.000' UNION ALL
SELECT 'Pawan kumar', 'Ramesh123', NULL, 1, '2014-01-04 16:50:23.000' UNION ALL
SELECT 'Ravi123', 'Sonu', 1, NULL, '2014-01-04 17:03:22.000' UNION ALL
SELECT 'Vineet123', 'Sonu', NULL, 1, '2014-01-04 17:26:01.000' UNION ALL
SELECT 'dev123', 'Ravi123', 1, NULL, '2014-01-05 19:35:16.000' UNION ALL
SELECT 'Mukesh123', 'Ravi123', NULL, 1, '2014-01-05 19:40:41.000' UNION ALL
SELECT 'poonam123', 'Vineet123', 1, NULL, '2014-01-05 19:49:49.000' UNION ALL
SELECT 'monu', 'Pawan kumar', 1, NULL, '2014-01-05 17:32:58.000' UNION ALL
SELECT 'Arti123', 'Pawan kumar', NULL, 1, '2014-01-05 19:54:35.000'
go
CREATE proc [dbo].[count_pairs]
@ParentID nvarchar(50)
as
begin
Declare @ParentSUM SMALLINT = 0
Declare @SubLeftID nvarchar(50)
Declare @SubRightID nvarchar(50)
SELECT @SubLeftID = CASE WHEN [IsLeft] = 1 THEN [ID] ELSE @SubLeftID END
,@SubRightID = CASE WHEN [IsRight] = 1 THEN [ID] ELSE @SubRightID END
FROM Associate_Income
WHERE ParentID = @ParentID
IF @SubLeftID IS NOT NULL AND @SubRightID IS NOT NULL AND EXISTS(SELECT 1 FROM Associate_Income WHERE [IsLeft] = 1 AND ParentID = @SubLeftID)
BEGIN
SET @ParentSUM = 1
;WITH Associate_Income_CTE AS
SELECT [ID], [ParentID], [IsLeft], [IsRight], 0 AS [Level]
FROM Associate_Income
WHERE [ParentID] = @ParentID
UNION ALL
SELECT RecursiveMember.[ID], RecursiveMember.[ParentID], RecursiveMember.[IsLeft], RecursiveMember.[IsRight], Level + 1
FROM Associate_Income RecursiveMember
INNER JOIN Associate_Income_CTE AnchorMember
ON RecursiveMember.[ParentID] = AnchorMember.[ID]
SELECT @ParentSUM = @ParentSUM + COUNT([ParentID])
FROM
SELECT [ParentID]
,'IsLeft' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsLeft] = 1
AND [ID] <> @ParentID --AND [ID] NOT IN (@SubLeftID, @ParentID)
AND [ParentID] NOT IN (@ParentID, @SubLeftID)
UNION ALL
SELECT [ParentID]
,'IsRight' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsRight] = 1
AND [ParentID] <> @ParentID
) AS Associate_Income
PIVOT
MAX([Value]) FOR [Direction] IN ([IsLeft], [IsRight])
) PVT
WHERE [IsLeft] IS NOT NULL AND [IsRight] IS NOT NULL
END
SELECT @ParentSUM
END
go
EXEC count_pairs 'Ramesh123'
go
DROP PROCEDURE count_pairs
DROP TABLE Associate_Income
Erland Sommarskog, SQL Server MVP, [email protected] -
Query to find the parent group name
what is/are the table name that i should use to find the parent name of the job?
thank you,
warrenHi Warren,
The parent group name (dbo.jobmst.jobmst_prntname) can be found within jobmst table.
For example, the below query will return parent name of a specified job:
SELECT dbo.jobmst.jobmst_prntname
FROM dbo.jobmst
WHERE dbo.jobmst.jobmst_name = 'Enter name of job here'
BR,
Derrick Au -
How to find the third highest salary by distinct the salary from deptno20,from employee table
how to find the third highest salary by distinct the salary from deptno20,by using employee table
You already asked this question, a half hour earlier:
https://forums.oracle.com/thread/2569985
and received a reply.
Do not multi-post to the forums.
These are user-to-user forums and everyone is posting because they volunteer to post and not because they get paid to post. Everyone else is paid exactly the same as you are paid to post here. When you multi-post is makes you appear as impatient and expecting instantaneous answers.
That is poor forum etiquette, approaching behavior similar to spamming the forums.
This duplicate post is locked. -
How to find the third highest salary from deptno20,from employee table
how to find the third highest salary from deptno20,from employee table
SELECT *
FROM emp;
EMPNO
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
7369
SMITH
CLERK
7902
12/17/1980
1000
3
20
7499
FEDERAL
SALESMAN
7654
2/20/1981
2000
4
30
7521
WARD
SALESMAN
7698
2/22/1981
3000
4
30
7566
JONES
MANAGER
7839
4/2/1981
4000
3
20
7839
MARTIN
SALESMAN
7698
9/28/1981
5421
4
30
7698
BLAKE
MANAGER
7698
5/1/1981
6222
4
30
7782
CLARK
MANAGER
7839
6/9/1981
5222
2
10
7788
SCOTT
ANALYST
7566
12/9/1982
5463
3
20
7839
KING
PRESIDENT
7902
11/17/1981
8543
2
10
7844
TURNER
SALESMAN
7698
9/8/1981
2124
4
30
7876
ADAMS
CLERK
7788
1/12/1983
2125
3
20
7900
JAMES
CLERK
7698
12/3/1981
5462
4
30
7902
FORD
ANALYST
7566
12/3/1981
2132
3
20
7934
MILLER
CLERK
7782
1/23/1982
5165
2
10
SELECT sal, deptno
FROM (SELECT a.*,
DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) r
FROM emp a
---- ORDER BY sal DESC
WHERE r = 3;
SAL
DEPTNO
5421
30
5165
10
2132
20
Regards ,
Friend
Message was edited by: MostWanted!!!! -
How to find the parent package
Hi,
The problem I'm trying to solve is, given an instance of a SSIS package being executed, I need to find the GUID and execution id of the package that calls it. According to the API (https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.package.aspx)
the Package class
has a property "Parent", which returns the instance of the container that contains the child package. In reality though, this doesn't seem to work. Here's what I did,
1. Create a child package that simply has a script task which writes a line to a file for debugging purpose.
2. Create a custom SSIS component in which the child package is called by the myPackage.Execute() method;
3. Given the reference myPackage, try to print the parent container id through the FireInfo() method from IDTSComponents interface.
What I got was an "reference not set to an object" error, which means the parent property is null. This leads me to wonder, when is the parent property set? Is it only set during the execution of the child package? I tried to access it both before
and after executing the child package, and in both cases the value was null.
My ultimate goal is to write the parent package id (and execution id) into the ssis log so as to easily trace the execution of packages. Another option to achieving this goal would be through passing values via parent package variables but that seems to
be too clumsy.
Any help / suggestion is greatly appreciated.
Regards,
AmosI have done the same thing via different way. Let me tell you how
Step 1: Create a log table
CREATE TABLE [dbo].[ExecutionLog](
[LogID] [int] IDENTITY(1,1) NOT NULL,
[ParentLogID] [int] NULL,
[Description] [varchar](50) NULL,
[PackageName] [varchar](50) NOT NULL,
[PackageGuid] [uniqueidentifier] NOT NULL,
[MachineName] [varchar](50) NOT NULL,
[ExecutionGuid] [uniqueidentifier] NOT NULL,
[Operator] [varchar](50) NOT NULL,
[StartTime] [datetime] NOT NULL,
[EndTime] [datetime] NULL,
[Status] [tinyint] NOT NULL,
[FailureTask] [varchar](64) NULL,
CONSTRAINT [PK_ExecutionLog] PRIMARY KEY CLUSTERED
[LogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[ExecutionLog] WITH CHECK ADD CONSTRAINT [FK_ExecutionLog_ExecutionLog] FOREIGN KEY([ParentLogID])
REFERENCES [dbo].[ExecutionLog] ([LogID])
GO
ALTER TABLE [dbo].[ExecutionLog] CHECK CONSTRAINT [FK_ExecutionLog_ExecutionLog]
GO
Step 2: On every package Create three Execute SQL Task
Execute SQL Task 1 : On begin of package
Execute SQL Task 2 : After completion of all task
Step 3: Now create two SP
For EQT #1
--Root-level nodes should have a null parent
if @ParentLogID <= 0 set @ParentLogID = null
--Insert the log record
insert into dbo.ExecutionLog(
ParentLogID
,Description
,PackageName
,PackageGuid
,MachineName
,ExecutionGuid
,Operator
,StartTime
,EndTime
,Status
,FailureTask
) values (
@ParentLogID
,@Description
,@PackageName
,@PackageGuid
,@MachineName
,@ExecutionGuid
,@operator
,getdate()
,null
,0 --InProcess
,null
set @logID = scope_identity()
EQT #2 On End
update dbo.ExecutionLog set
EndTime = getdate() -
,Status = case
when Status = 0 then 1 --Complete
else Status
end --case
where
LogID = @logID
You can create similar SP for OnError if you want
Step 4: Now create two variables LogId & parentLogId Int default value 0
Step 5: Step up parent package variable configuration for logId like below
Step 6: Call these SP in respective execute SQL task
Hope this will help
Glad to help! Please remember to accept the answer if you found it helpful. It will be useful for future readers having same issue.
My Profile on Microsoft ASP.NET forum -
How to find which Port has the highest traffic (both in/out) in switch
Hello,
I have a 3550 switch with 48 port having 12.1 code.
Need to know which port is causing the highest traffic , i mean to track which user is downloading/uploading the most.
I was able to track this in CATOS with the command sh top and that will tell the port, but in IOS based switches i was not able to find
Can some one help.You can try with the following command:
show interfaces summary
Output shows the traffic for all ports instead of the top one only, but you can find the top from this output. Or you can install an MRTG or Cacti for monitor the used bandwith.
bye
FCS
Please rate me if I helped. -
I have an IPad Model MC497LL with version 4.2.1 (8C148) where do I find system updates to get this device to the highest version possible for this model?
Go back to the article you asked this question from, ignore the instructions for updating it wirelessly, scroll down, and follow those for updating it from iTunes on a computer.
(93330)
Maybe you are looking for
-
Everytime when I perform a Full Crawl on the Central Administraion page, this error will appear and the crawl process will run into an infinite loop and nothing crawl success. I have tried delete and re-create the crawling content sources, start/stop
-
Created a new account - now how do I hide documents?
My friends are always grabbing for my computer for quick internet visits, etc. - but I have some legal documents I'd rather them not see. I created a new account thinking this would solve the issue, but while it reset my internet and applications - a
-
How do I turn on the wi fi to share internet
HI, I just installed Snowleopard wanted to share to the internet but is not working. Any suggestions?
-
http://discussions.apple.com/message.jspa?messageID=8670204 http://discussions.apple.com/message.jspa?messageID=8670132 http://discussions.apple.com/message.jspa?messageID=8670131 http://discussions.apple.com/message.jspa?messageID=8670030 http://dis
-
Dynamically set ViewObject where clause dynamically from Java bean
I have a requirement to display all of the records from a table when the JSP is first brought up, so my View Object looks like this: "select emp_name from emp" Then the users wants to ability to pass paramters to that View Object to refine the list s