Query on Hierarchical data
Hi All,
I have below scenerio
Input as:
outlet
new_outlet
a
b
b
c
c
d
d
a
aa
bb
bb
cc
cc
aa
l
m
m
n
x
y
y
x
expected output will be:
a
d
b
d
c
d
aa
cc
bb
cc
l
n
m
n
x
y
y
x
please help me on this .I tried with connect by prior clause but not able to get exact output.
Many thanks,
Hi All,
Actually,there are 3 scenerios :
case1: recursive data
input data:
outlet
new_outlet
a
b
b
c
c
d
d
a
output data:
a
a
b
a
c
a
d
a
case 2: Non recursive data with multiple rows
input data:
l
m
m
n
output data:
l
n
m
n
Case 3:Non recursive data with single rows
input data:
x
y
output data:
x
y
Please help me on this.
Thanks,
Similar Messages
-
AdvancedDataGrid - create Array (cfquery) with children for hierarchical data set
I'm trying to create an AdvancedDataGrid with a hierarchical
data set as shown below. The problem that I am having is how to
call the data from a ColdFusion remote call and not an
ArrayCollection inside of the Flex app (as below). I'm guessing
that the problem is with the CFC that I've created which builds an
array with children. I assume that the structure of the children is
the issue. Any thoughts?
Flex App without Remoting:
http://livedocs.adobe.com/labs/flex3/html/help.html?content=advdatagrid_10.html
<?xml version="1.0"?>
<!-- dpcontrols/adg/GroupADGChartRenderer.mxml -->
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dpHierarchy:ArrayCollection= new
ArrayCollection([
{name:"Barbara Jennings", region: "Arizona", total:70,
children:[
{detail:[{amount:5}]}]},
{name:"Dana Binn", region: "Arizona", total:130, children:[
{detail:[{amount:15}]}]},
{name:"Joe Smith", region: "California", total:229,
children:[
{detail:[{amount:26}]}]},
{name:"Alice Treu", region: "California", total:230,
children:[
{detail:[{amount:159}]}
]]>
</mx:Script>
<mx:AdvancedDataGrid id="myADG"
width="100%" height="100%"
variableRowHeight="true">
<mx:dataProvider>
<mx:HierarchicalData source="{dpHierarchy}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name"
headerText="Name"/>
<mx:AdvancedDataGridColumn dataField="total"
headerText="Total"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider
dataField="detail"
renderer="myComponents.ChartRenderer"
columnIndex="0"
columnSpan="0"/>
</mx:rendererProviders>
</mx:AdvancedDataGrid>
</mx:Application>
CFC - where I am trying to create an Array to send back to
the Flex App
<cfset aPackages = ArrayNew(1)>
<cfset aDetails = ArrayNew(1)>
<cfloop query="getPackages">
<cfset i = getPackages.CurrentRow>
<cfset aPackages
= StructNew()>
<cfset aPackages['name'] = name >
<cfset aPackages
['region'] = region >
<cfset aPackages['total'] = total >
<cfset aDetails
= StructNew()>
<cfset aDetails['amount'] = amount >
<cfset aPackages
['children'] = aDetails >
</cfloop>
<cfreturn aPackages>I had similar problems attempting to create an Array of
Arrays in a CFC, so I created two differents scripts - one in CF
and one in Flex - to build Hierarchical Data from a query result.
The script in CF builds an Hierarchical XML document which is then
easily accepted as HIerarchical Data in Flex. The script in Flex
loops over the query Object that is returned as an Array
Collection. It took me so long to create the XML script, and I now
regret it, since it is not easy to maintain and keep dynamic.
However, it only took me a short while to build this ActionScript
logic, which I quite like now (though it is not [
yet ] dynamic, and currently only handles two levels of
Hierarchy):
(this is the main part of my WebService result handler)....
// Create a new Array Collection to store the Hierarchical
Data from the WebService Result
var categories:ArrayCollection = new ArrayCollection();
// Create an Object variable to store the parent-level
objects
var category:Object;
// Create an Object variable to store the child-level
objects
var subCategory:Object;
// Loop through each Object in the WebService Result
for each (var object:Object in results)
// Create a new Array Collection as a copy of the Array
Collection of Hierarchical Data
var thisCategory:ArrayCollection = new
ArrayCollection(categories.toArray());
// Create a new instance of the Filter Function Class
var filterFunction:FilterFunction = new FilterFunction();
// Create Filter on the Array Collection to return only
those records with the specified Category Name
thisCategory.filterFunction =
filterFunction.NameValueFilter("NAMETXT", object["CATNAMETXT"]);
// Refresh the Array Collection to apply the Filter
thisCategory.refresh();
// If the Array Collection has records, the Category Name
exists, so use the one Object in the Collection to add Children to
if (thisCategory.length)
category = thisCategory.getItemAt(0);
// If the Array Collection has no records, the Category Name
does not exist, so create a new Object
else
// Create a new parent-level Object
category = new Object();
// Create and set the Name property of the parent-level
Object
category["NAMETXT"] = object["CATNAMETXT"];
// Create a Children property as a new Array
category["children"] = new Array();
// Add the parent-level Object to the Array Collection
categories.addItem(category);
// Create a new child-level Object as a copy of the Object
in the WebService Result
subCategory = object;
// Create and set the Name property of the child-level
Object
subCategory["NAMETXT"] = object["SUBCATNAMETXT"];
// Add the child-level Object to the Array of Children on
the parent-level Object
category["children"].push(subCategory);
// Convert the Array Collection to a Hierarchical Data
Object and use it as the Data Provider for the Advanced Data Grid
advancedDataGrid.dataProvider = new
HierarchicalData(categories); -
Tree interface concept for hierarchical data creation/modification
I am designing an interface for hierarchical data creation and maintenance. The interface will have to provide all basic data modifications options:
edit an existing node, add new child/parent/sibling, as well as removing, sorting, dragging and dropping nodes around. Flex tree control is fully capable of all these functions while coding is not going to be a simple task. Has anyone worked on something like this? Any conceptual ideas?
ThanksWOW Odie! You're awesome !! It worked like a charm, I created a view as you suggested:
CREATE OR REPLACE FORCE VIEW "VIEW_TASKS_PROJECTS_TREE" ("ID", "PARENT_ID", "NODE_NAME") AS
SELECT to_char(id) as id
, null as parent_id
, project_name as node_name
FROM eba_task_projects
UNION ALL
SELECT to_char(id)
, to_char(project_id)
, task_name
FROM eba_task_tasks;
And then I created a new tree with the defaults and customized the Tree query a bit (just added the links really):
select case when connect_by_isleaf = 1 then 0
when level = 1 then 1
else -1
end as status,
level,
"NODE_NAME" as title,
null as icon,
"ID" as value,
null as tooltip,
'f?p=&APP_ID.:22:&SESSION.::NO::P22_ID,P22_PREV_PAGE:' || "ID" || ',3' as link
from "#OWNER#"."VIEW_TASKS_PROJECTS_TREE"
start with "PARENT_ID" is null
connect by prior "ID" = "PARENT_ID"
order siblings by "NODE_NAME"
Thanks man, you saved me a lot of time and headaches :) -
Hierarchical data maintainance
Hello,
I have a table (Parent - Child).
There is a requirement to maintain this table, thats the hierarchy of the oraganisation.
So, every quater they will be updating the table.
They will be importing the data through an excel and in that excel there are 3 action items,
=> Insert, Update and Delete (logical delete).
CREATE TABLE PARENT_CHILD_TBL
( "ID" VARCHAR2(6 BYTE) NOT NULL ENABLE,
"ID_DESC" VARCHAR2(200 BYTE),
"ID_LEVEL" VARCHAR2(200 BYTE),
"PARENT_ID" VARCHAR2(200 BYTE)
For Update:
Any ideas, What all validation can come for an updation of an hierarchical data in general.
Like
= how to derive the level value at database side when the id is updated to some other level.
= How to maintain the relation.
A -> B -> D ( A is the grand parent here).
A -> C
eg: if B is updated as parent node of A, then we should throw error (cyclic data).
Any more validations for hierarchical data, anybody can suggest and the way to go for it will be helpful.
Thanks !!Hi,
You can use the LEVEL psudo-column in a CONNECT BY query:
SELECT p.*
, LEVEL
, CASE
WHEN TO_CHAR (LEVEL, 'TM') = id_level
THEN 'OK'
ELSE ' *** BAD ***'
END AS flag
FROM parent_child_tbl p
START WITH parent_id = '0000'
CONNECT BY parent_id = PRIOR id
Output from the sample data you posted (where all the level_ids are correct):
PARENT
ID ID_DESC ID_LEVEL _ID LEVEL FLAG
A ROOT 1 0000 1 OK
B CHILD1 2 A 2 OK
D SUB CHILD1 3 B 3 OK
C CHILD2 2 A 2 OK
If you only want to see the rows where id_level is wrong, then you can use LEVEL in a WHERE clause.
Maybe you shouldn't bother manually entering id_level at all, and just have a MERGE statement populate that column after all the other data is entered.
Why is the id_level column defined as a VARCHAR2, rather than a NUMBER?
Given that it must be a VARCHAR2, why does it need to be 200 bytles long? -
Getting data in a query on last date of all previous months
Dear Experts,
I need your help with a query.
I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
Please advise how to achieve this is SQL query.
Thanks & regards,
NitinHi,
Try this:
Select *
from(
SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
FROM ORDR T0
WHERE T0.[DocStatus] = 'o' and T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
group by t0.cardcode,docdate,T0.[DocNum]) S
pivot
(count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
Note: Replace Cvt01,02...with your customer code.
Thanks & Regards,
Nagarajan -
POWER QUERY Get External Data From File From Folder (Excel 2013)
Hi,
Beginner's question :
What could be the use of the query on a folder : we just get a list of files with their path. What can we do with that?
ThanksHi,
Do you want to combine data from multiple Excel Files in the same folder path into one table? If I understand correct, we can add a custom column to import the data.
After we getting a list of files with their path, the Query Editor window will activate to show you a table containing a record for each file in the chosen directory. These will provide our function with the needed FilePath and FileName parameters.
Function sample: File name([Folder path],[Field name]
For more detailed steps, please see the article:
http://datapigtechnologies.com/blog/index.php/using-power-query-to-combine-data-from-multiple-excel-files-into-one-table/
Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
Data driven subscription query returns no data
We have a data driven subscription on SSRS 2008 R2. The columns in the query are tied to one or more parameters of the report. When we run the subscription and if the query does not return any rows, I was hoping that the subscription will not start; however,
instead, to my surprise, I got error stating..."Parameter XYZ value can't be null". How to avoid this error and keep subscription from running in this situation?
Example: I have a report that required employeeID as a parameter. I have a query (step 3: data driven subscription) that fetches employee ID based on some criteria. If there is no row returned by the query; It throws error on report stating "Parameter
EmployeeID can't be null."
Nehal JainHello Nehal -
Try adding a UNION ALL to your parameter dataset query like
UNION ALL SELECT NULL AS EmployeeID , ..
Just check accordingly. I ll revert again based on this , got a priority now.
Happy to help! Thanks. Regards and good Wishes, Deepak. http://deepaksqlmsbusinessintelligence.blogspot.com/ -
Web Analysis Error -- Error while executing query and retrieving data
Regarding Web Analysis:
We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error.
The error is:
Error while executing query and retrieving data.; nested exception is:
com.hyperion.ap.APException: [1033] Native:
1013033[Thu Oct 22 09:08:17
2009]server name/application name/database name/user name/Error91013033)
ReportWriter exit abnormally
Does anyone have any insight into what is going on?
My version information is:
Hyperion System 9 BI+ Analytic Administration Services 9.3.0.1.1 Build 2
Web Analysis 9.3.0.0.0.286
Thanks in advance for your help.
DaveWHi,
And also click on check option by opening the query in Query designer,as Mr . Arun suggested.
And if you get any error in checking, see the long message(detail).
With rgds,
Anil Kumar Sharma .P -
Select query to read data from a view
Hi friends,
We have been using a query to read data from a custom view which used to work perfectly. Now the program sits at that select query forever. We are able to extract same data from se16. Not sure what could be the problem.
Thanks in advance.Dev
Have a look at the Table Index for the tables involved in the View... I think there is some change in the Indexes.. (Add / Remove / Change)
Thanks
Amol Lohade -
Error when executing a query on master data
Hi Friends,
When I execute a query fon Master Data Characteristic infoObject ( 0BPARTNER ) from BEx Analyzer I got the below error. 0BPARTNER contains 15 attributes. I am getting the below error only for this query. Rest all other queries are working good with the same BEx Analyzer.
<b>An error occured in the communication with the BW Server.
Due to this connection has to be closed.</b>
<b>Detailed Description:
The system is configured incorrectly.</b>
Please tell me what could be the problem? How to overcome this?
Thanks,
SasiHi Arun,
Before the execution of query I did that. And it was ' Query is Correct'.
Any more ideas?
Thanks,
Sasi. -
How to use a query in matrix data retrive
hai everybody
how to use a query in matrix data retrive...
pls ..If u have created a UDT to store the data then U can retrive the data through recordset.
oRecordset.doquery("SQL Statement")
If u have taken the DB Data source to Manipulate then
then type
oMatrix.flushtoDataSource
then
U can retrive the data through DB Data source.
-Manmath -
Query regarding the data type for fetcing records from multiple ODS tables
hey guys;
i have a query regarding the data type for fetcing records from multiple ODS tables.
if i have 2 table with a same column name then in the datatype under parent row node i cant add 2 nodes with the same name.
can any one help with some suggestion.Hi Mudit,
One option would be to go as mentioned by Padamja , prefxing the table name to the column name or another would be to use the AS keyoword in your SQL statement.
AS is used to rename the column name when data is being selected from your DB.
So, the query Select ename as empname from emptable will return the data with column name as empname.
Regards,
Bhavesh -
Query from the data abse and pass values to a pdf form
query from the data abse and pass values to a pdf form
Hello
Hello i have this html report that i have written to output a
report.
now, i am assigned to pass the same fields to a pdf form so
the fields in the adaobe form can be populated or the term
Pre-populate the form.
can anyone help me get started.
first i would like to know if it can be done.
second, what do i need to get started (tools )
third how do i do this.
i am really lost at this point.
can anyone give me tips in how to approach this
subject??It can be one using Adobe Acrobat Designer which is packaged
with Acrobat
Professional Pro 7. It uses all XML to create and populate
forms.
If you had the time, you can also create <cfdocument
type="pdf"> to have
them ready and just pass the info to it so it autogenerates
the PDF on the
fly. -
Hi,
I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
Here are my columns:
current output:
JOB_ID JOBDATE GROUP PATH OUTCOME FAILED LEVEL ASSET
3400908 7/27/2012 10:01:18 AM polA target1 Success 0 incr clone1
3400907 7/27/2012 10:01:09 AM polA target1 Failed 0 incr clone1
3389180 7/23/2012 10:01:14 AM polA target1 Failed 1 incr clone1
3374713 7/23/2012 10:01:03 AM polA target1 Success 0 incr clone1
3374712 7/22/2012 11:24:32 AM polA target1 Success 0 Full clone1
3367074 7/22/2012 11:24:00 AM polA target1 Failed 1 Full clone1
3167074 7/21/2012 10:01:13 AM polA target1 Success 0 incr clone1
336074 7/21/2012 10:01:08 AM polA target1 Success 0 incr clone1
desired output:
JOB_ID JOBDATE GROUP PATH OUTCOME FAILED LEVEL ASSET
3400908 7/27/2012 10:01:18 AM polA target1 Success 0 incr clone1
3374713 7/23/2012 10:01:03 AM polA target1 Success 0 incr clone1
3374712 7/22/2012 11:24:32 AM polA target1 Success 0 Full clone1
3167074 7/21/2012 10:01:13 AM polA target1 Success 0 incr clone1
Here is a code I am trying to use without success:
select *
from
(selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
where rn = 1
order by jobdate desc;Thanks,
-AbeHi, Abe,
You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
If so, this is what you want:
WITH got_r_num AS
SELECT j.* -- or list columns wanted
, ROW_NUMBER () OVER ( PARTITION BY group_id -- GROUP is not a good column name
, path
, asset
, TRUNC (jobdate)
ORDER BY CASE outcome
WHEN 'Succcess'
THEN 1
ELSE 2
END
, jobdate DESC
) AS r_num
FROM job_table j
WHERE outcome IN ('Success', 'Failed')
-- AND ... -- Any other filtering, if needed
SELECT * -- or list all columns except r_num
FROM got_r_num
WHERE r_num = 1
;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
It looks like you posted multiple copies of this thread. I'll bet that's not your fault; this site can cause that. Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now. -
Select Query Based on date condition
Hi ,
Is it Possible.
i want to run select query based on date condition.
Eg...
if the date between 01-jan-01 and 01-jan-05 then
select * from table1;
if the date between 02-jan-05 and 01-jan-08 then
select * from table2;
Becaz i have data in 2 diffrent tables , based on the date condition i wnt to run the select statement to diffrent tables.
i dont want plsql here Just SQL needed.
thanks,
-R
Edited by: infant_raj on May 5, 2009 11:48 PMHelo Kanish,
this is not the one i was asking..
wht i mean was .
i use bind variable to get date while running the select statement , once i get the date then i want to choose any one of the table to run select query.
EG..
select col1,col2 from table1 where date between only if 01-jan-01 and 01-jan-05;
select col1,col2 from table2 where date between only if 02-jan-05 and 01-jan-08;
Run any one of the two . not all
thanks,
_raj
Maybe you are looking for
-
Firefox stops responding. I need to exit and restart or reboot the computer.
I do not get an error message - the application simply hangs up during the opening sequence or stops responding when open. Also, some links within web sites do not work. Example: The embedded print command for Google Maps does not work, however, the
-
how to download the BSP page? i would like to download total BSP page contents.
-
PRICING_SUBSCREEN_PBO alternate
hi, I am using PRICING_SUBSCREEN_PBO to get the data for the sales details, and it is working fine and i am moking use of table YKOMV from the funtion modiule,but it is taking more time if i run this report for a week because of this function module,
-
After adjusting white balance in ACR, images are opening in Ps at a different size.
Can anyone explain like I'm 5 why this is happening, and how to prevent it? Thanks! Negatives are scanned at 3200dpi, and 24bit depth. This is the metadata from Bridge. Default settings in Camera Raw After opening in Photoshop.
-
Hi I need to boot image in "French". I view this: http://www.petervanderwoude.nl/post/how-to-change-the-language-in-windows-pe-via-configmgr-2012/ I change 1031 for 1036, i check in <ConfigMgrInstallFolder>\OSD\bin\x64\0000040c\tsres.dll is present (