Joe Celko Nested Set Model: How To Compute The Lft And Rgt Cols

Jul 3, 2006

Hi,

With reference to http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=235427
I want the "sql stmt" which wud give the lft and rgt col values..

i am reading his book but cant understand :eek: where he explains
wat lft and rgt cols are..

"The root is always (lft,rgt) (1, 2*(Select count(*)from table) and leaft nodes are (lft+1=rgt)" :S

View 3 Replies


ADVERTISEMENT

Celko Nested Sets Vs. Linked Tables

Feb 9, 2004

Hi,

I am trying to revamp our product database with a view to making it search-optmised and would like some guidance (or confirmation of method, if you will!!). We currently use a three table structure (Product, Brand, Cat(egory)) along the lines of :

create table product
(prod_id int not null,
brand_id int not null,
cat_id int not null,
other stuff e.g. tech. specs, displayed text on web page, etc....
)

with corresponding brand_id and cat_id in the other tables. While this seems relationally sound I see it as being inefficient for searching, particularly after reading the theory behind nested sets.

A new function I am building will enable users to drill down through the product list or runs searches against all or part of the db :

e.g. all products from one category,
all products fitting certain search criteria,
products from several selected brands fitting certain criteria,
and any combination of the above you can think of!

The problem is, not all products have the same criteria list (in fact I would be surprised if any did) and may also be of more than one category (a digital camera with movie mode might easily fit into the digital camcorder search). I think I am correct in that a nested set would make the structure fit the requirement - things like criteria, displayable text, etc. could be nodes in their own right and each logical level might have its own criteria. For example, if a category is selected then certain text must be displayed and could list further categories or products. The next level down would then require its own displayable text - I am mainly thinking about SEO tags here. Also, I am not precious about retaining the current table structure and would like an open ended solution where I can add further data/functionality in a dynamic fashion, which nested sets seem to embody.

Does this make sense to anybody coz I think I've confused myself even more!!

Thanks in advance,

G

View 14 Replies View Related

Help With Celko's Tree Model

Jul 20, 2005

hello i have implemented joe celko's model to store heirarchy and itworks well and nicei have a question about SQLthis is the actual tablemember side left right------------------------------------------nancy L 1 36andrew L 4 21steven R 5 12ina L 6 7david R 10 11margaret L 13 20ann R 14 15laura L 18 19janet R 24 35michael L 25 30dan R 26 27ron L 28 29robert R 33 34the Side column is to tell its left, or right. this is a binaryheirarcy.i have this problem i have to solve, im still banging my head. Ifgiven the member'Nancy' , i need to find left-most(Laura) and right-most(Robert)'Janet' = left most is ron, right most is robert'Andrew = left most is laura, right most is DavidHope u get my plan. could u help me with the sql ?

View 3 Replies View Related

Nested Set Model

Jan 30, 2006

hi guys,

i have the following category table...

CREATE TABLE [dbo].[categories] (
[cat_id] [int] IDENTITY (1, 1) NOT NULL ,
[dModified] [datetime] NULL ,
[dCreated] [datetime] NULL ,
[cat_parent_id] [int] NULL ,
[cat_lft] [int] NULL ,
[cat_rgt] [int] NULL ,
[cat_image] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[cat_sort_order] [int] NULL
) ON [PRIMARY]
GO

i now wish to add a levels column which indicates (funnily enough :)) which level each record is on starting from 1.

is there a query i can use which will output for me the levels based on the child/parent relationship?

regards
mike

View 3 Replies View Related

Updating Nodes In A Nested Set Model

Sep 14, 2006

We have a nested set L and R design in our database.
The design allows multiple instances of nodes in the hierarchy. Each node has a combination of node name and its instance id as the primary key. We also maintain a unique_qty column that has the unique number of nodes below a particular node. This unique qty basically ignores the multiple instances of nodes below it and counts only the distinct node names(ignoring their instance ids).
the problem that im facing is...how do i update the unique_qty when i perform any move in the tree.
UPDATE Hierarchy
SET unique_qty = ( SELECT COUNT(DISTINCT node_name) FROM Hierarchy AS H2 WHERE H2.L > Hierarchy.L AND H2.R < Hierarchy.R )

I am using the above query to find out the unique_qty when i initially populate the table.
My question is.. when i make a move of a subtree within the hierarchy, then i need to update this unique_qty for the source parents and the destination parents of the subtree( and the unique_qty for eah node in the subtree being moved remains the same ).
I had two ideas on how to update the parent nodes of the subtree:

1) for each node in the path to the root in the hierarchy, from the parent nodes( both source side and destination side) recalculate the unique_qty

2) for each node in the subtree find out until what level in the path to the root, we need to update the unique_qty, and then update only those unique_qtys

any suggestions on my methods? which one is better? any more ideas on how to do this??

View 4 Replies View Related

Updating Nodes In A Nested Set Model

Sep 14, 2006

We have a nested set design in our database.
The
design allows multiple instances of nodes in the hierarchy. Each node
has a combination of node name and its instance id as the primary key.
We also maintain a unique_qty column that has the unique number of
nodes below a particular node. This unique qty basically ignores the
multiple instances of nodes below it and counts only the distinct node
names(ignoring their instance ids).
the problem that im facing is...how do i update the unique_qty when i perform any move in the tree.

Thanks in advance
satya phani

View 4 Replies View Related

SSIS Data Mining Model Training Transform (Nested Tables)

Oct 26, 2006

I can't figure out how to put nested tables into the Data Mining Model Training Transform (SSIS). I can do a simple case table, but how do you get those nested tables with DM Training Transformation? Any ideas? Samples?

Thanks in advance,

-Young K

View 3 Replies View Related

Why Should We Sample Nested Table Separetely For Data Mining Model Trainings?

Dec 1, 2006

Hi, all here,

Thank you very much for your kind attention.

I dont think we should sample any nested tables for data mining model training? Since I think any nested tables are bound to the case table. Therefore whenever we sample the case table, the nested tables are like any other input attributes within the case table to be rectrieved as inputs accordingly?

Thank you very much for any guidance to clear my confusion.

With best regards,

Yours sincerely,

 

 

View 3 Replies View Related

Question For --CELKO--

Jul 20, 2005

Greetings,I think I saw an article yesterday in which you told someone not to makean Identity column a primary key. I seem to remember you sayingsomething like "It undermines the entire foundation of the relationalmodel."I've been thinking about that all night and I think I understand whatyou're saying, but I have some questions.I think you're saying that if the real key in a 3 attribute (heh, heh.didn't say fields. heh heh) tuple (heh heh) is a combination of thethree attributes, then that's what you should use as a primary key.Do you then advocate never using an Identity attribute? Or is itacceptable (in the relational model) to have an Identity attribute touse as a handle to the row, and for attributes in other tables to use asthe target for a foreign key?Thank you,-- Rick

View 18 Replies View Related

Report Model Deployment : The Model ID Of The Submitted Model Must Match That Of The

Dec 5, 2005

Running 2005 Beta 3 Refresh.  When I first deploy, it works fine. Subsequent deployments yield the following error:

View 9 Replies View Related

XML To Cols

Oct 5, 2006

I have a XML column in my source DB. Is there any way possible using SSIS to convert the XML to ordinaty cols (varchar) in the destination db.

I am using Sql 2k5.

thanks in advance

View 1 Replies View Related

Query From Two Cols !?

Jun 27, 2007

my table

id; part_name ; part_desc
01; xpto ; descr
02; qwerty ; azerty
03; azerty ; descr xpto

I want to search from two columns
something similar to :

SELECT * FROM tools WHERE (part_name LIKE @parameter_search or part_desc LIKE @parameter_search);

If i search for "xpto" only the first line would show.

How can i solve/go around this?

View 4 Replies View Related

Distinct Cols Of More Than One

Aug 30, 2005

Hi

There is a table which has repeated values in more than one col.
I want to view all the distinct values for both the cols

for eg

col1 col2 col3
A B D
A B E
B C E
B C F


I want the output as

col1 col2
A B
B C


cheers
Vic

Vicky

View 8 Replies View Related

How To: Find Cols In A Table

Jan 12, 2002

I'd like to know if I can make one proc/cursor that I can pass only a table name and it will determine what cols exist in the table?

AND, what is the syntax for such a query?


I will be receiving data back where I will receive the accountID and only the deltas will have values all other columns will be null.

My proc will update an existing record, updating the specific col when an accountID exists, it will create a new record if the accountID does not exist.

I'd like to search all the cols getting their names and values when not null.

I can construct a proc for each table searching each col by known name.

However, I'd like to know if I can make one proc/cursor that I can pass only a table name and it will determine the cols?

All my tables start with cols AccountID and end with RecID with any number of cols inbetween.

TIA

JeffP...
cross posted to ms.pub.mssqlserver.programming

View 2 Replies View Related

Two Identity Cols In Table

Jul 14, 2006

Hi,

How can we use two identity column (with identity property) in table ?

GK


gk

View 5 Replies View Related

How To Simply Join Cols Together?

Jun 5, 2007

I have about 30 tabs with same struture.
I want to simple put column 2 in all 30 table in a new table without joining on anything. Is there a way to do that?
Thanks
JP

View 3 Replies View Related

Display Row Data As Cols

Jun 6, 2006

I have data in rows that I need to aggregate and display in a columnar fashion and I haven't been able to figure out how to do it. A simplified version of the data as it is stored in the table:

Station Month Day Reading

1 1 1 100

1 1 2 200

1 1 3 300

1 2 1 400

1 2 2 500

And I would like to create a query that returns:

Station Month Day 1 Day 2 Day 3

1 1 100 200 300

1 2 400 500

Any help you can provide or tips to steer me in the right direction are much appreciated.

Dianne Siebold

View 6 Replies View Related

Query Single Col Into Several Cols Result Set

Oct 24, 2004

Hello,

I have a table with 1 column containing numeric values, and I need to create a query which displays the count of values for each set of conditions. For example, if the table contains the values 1,2,3,4,5 and 6, the output of the query should look like this:

L M H
-----------------------
3 2 1

(L are values below 4, M between 4 and 5, H is 6 and above)

Any suggestions?

TIA

View 1 Replies View Related

How Can I Get Primary Key Col And Other Two Cols In The Same Table Become One To One Relationship.

Jun 12, 2006

For ex.

Table Match_List ( MatchID, UserID_A, UserID_B)

constraints like

MatchID primary key

UserID_A <> UserID_B

unqiue index (UserID_A,UserID_B)

but I wish to exclude duplicated rows like 1,1,2 & 2,2,1,

cause UserA to UserB, and UserB to UserA are the same thing.

How can I get this?

View 7 Replies View Related

SQl Query... Multiple Cols To Single XML.

Oct 12, 2006

Hi I have a table which has couple of name cols and 10 varchar columns. The requirement was to retain the first two cols but convert the 10 cols into a single XMl.

the table has this schema;


ManagerName varchar
UserName varchar
TextField1 Varchar
TextField2 Varchar
TextField3 Varchar
TextField4 Varchar
TextField5 Varchar
TextField6 Varchar
TextField7 Varchar
TextField8 Varchar
TextField9 Varchar
TextField10 Varchar

I wrote a query like;

SELECT

TPD.[NameId]
,CrtdUser.[UserId]
from [Olddb_DB] TPD
join

[NewDB]..[Manager]CrtdUser
on
Crtduser.managerName = TPD.ManagerName
join
[NewDB]..[Users]Users

on
Users.[loginDetail] = TPD.[UserName]


to get the cols other than the XML

/*********/

SELECT

XmlDat.[textField1],

XmlDat.[textField2],

XmlDat.[textField3],

XmlDat.[textField4],

XmlDat.[textField5],

XmlDat.[textField6],

XmlDat.[textField7],

XmlDat.[textField8],

XmlDat.[textField9],

XmlDat.[textField10],

XmlDat.[textField11],

XmlDat.[textField12]

from

[olddb_db]..[DETAIL_DEF] XmlDat,[NEWDB]..[Detail_Def]TPD

where TPD.Name = XmlDat.Name

for XML AUTO, ELEMENTS

and this query to convert all the varchar cols to a XML. Now the problem is I am not sure of how to combine both these queries to Insert into the new table.

Can someone guide me in this

the destination table looks like

Name (Varchar)

UserId (int)

UserVal_XMl (XML)





Thanks in advance

View 3 Replies View Related

Compute The Age

Mar 5, 2007

Hi all. How could i get the age of the employees given the birthdate.

table - personalinfo

name birthdate
john 2/15/2004 12:00:00 AM
peter 2/15/2003 12:00:00 AM
jon 2/15/2001 12:00:00 AM
mike 2/15/2000 12:00:00 AM
sam 2/15/2002 12:00:00 AM

Thanks
-Ron-

View 8 Replies View Related

How To Widen Subtotal Col Without Widening Data Cols?

Jul 28, 2007


Hello ,

I need to make the automatic subtotal column in most right position in a matrix wider than the data columns , i faild so far and discovered that its width is proportional to the data column width , its logic for the total column to be wider since its value is sum(all left data columns)

any way around this ?

thanks
Bassam

View 1 Replies View Related

COMPUTE Clause

Feb 2, 2008

I run SELECT statement with a COMPUTE clause,columns in the select list overrides on aggregate functions in COMPUTE clause.
why was overrided?
how show  output COMPUTE clause?
SELECT     NUMBERFROM         Table_1COMPUTE AVG(NUMBER)
Result:
NUMBER
1
56
78
89
56
 
Thanks,mohsen

View 3 Replies View Related

Select With A COMPUTE

Nov 9, 2007

Is there a way to change the column headings when using a compute? I have the following code:


Select IP_address, Caption1, VendorIcon, InterfaceID, Caption2, InterfaceIcon, In_Maxbps, Out_Maxbps, DateTime1

from #test

WHERE InterfaceID IN('144', '154')

ORDER BY InterfaceID

COMPUTE max(In_Maxbps), max(OUT_maxbps), min(OUT_maxbps), avg(OUT_maxbps)

BY InterfaceID


The compute gives me 2 columns with the heading max. I would like to change those headings.

Thanks.

View 4 Replies View Related

Compute Column In View...

Mar 11, 2006

I have a SQL table that consists of columns A, B and C.  I am trying to construct a view consisting of all columns (i.e. A, B, C) and a computed column.  This computed column has the following logic:
If B is blank or null then  NewColumn = A + ' - ' C
else
 NewColumn = A + ' - ' + B
I am just wondering how the SQL statement should look like....
 

View 2 Replies View Related

Compute And Update In One Statement

Jun 13, 2008

Hi Guys, got a problem.
I am trying to create a table of summarized fees. I was unable to do a Insert command so I settled for an Update command. But I ran into this error msg which I’m not sure how to fix. Can anyone see the problem or is it not even possible to Update and Compute in the same statement? Do I have to do a sub query?

Update FEE_SUMs_20080402
SET LOAN_Num = F.DDLOAN, Fee_Amt = F.DDMFEE
FROM FEE_Recs AS F
INNER JOIN dbo.Addr_20080402 ON
Account_Num = F.DDLOAN
ORDER BY F.DDLOAN
COMPUTE SUM(F.DDMFEE) BY F.DDLOAN

Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'ORDER'.

View 3 Replies View Related

Finding Mismatched Rows Between Identical Tables Based On 2 Or More Cols

Jun 8, 2007

CREATE TABLE [RS_A] ([ColA] [varchar] (10)[ColB] [int] NULL)CREATE TABLE [RS_B] ([ColA] [varchar] (10)[ColB] [int] NULL)INSERT INTO RS_AVALUES ('hemingway' , 1)INSERT INTO RS_AVALUES ('vidal' , 2)INSERT INTO RS_AVALUES ('dickens' , 3)INSERT INTO RS_AVALUES ('rushdie' , 4)INSERT INTO RS_BVALUES ('hemingway' , 1)INSERT INTO RS_BVALUES ('vidal' , 2)I need to find all the rows in A which do not exist in Bby matching on both ColA and ColBso the output should bedickens 3rushdie 4So if i write a query like this , I dont get the right result setSELECT A.ColA, A.ColBFROMRS_A AINNERJOIN RS_B BONA.ColA <B.ColAORB.ColB <B.ColBBut if i do the following, i do get the right result, but followingseems convoluted.SELECT A.ColA, A.ColBFROMRS_A AWHERE ColA + CAST(ColB AS VARCHAR)NOT IN (SELECT ColA+CAST(ColB AS VARCHAR) FROMRS_B B)

View 6 Replies View Related

Compute Sums In Select Query

Dec 24, 2003

i have this query and would like to have a sum for each column. how can i phrase the compute line please ?

select office as Office
, Sum(Case (role) when 'ebp' then 1 else 0 end) as 'EBP'
, Sum(Case (role) when 'support' then 1 else 0 end) as 'Support'
, Sum(Case (role) when 'Awaiting Disposal' then 1 else 0 end) as 'Awaiting Disposal'
, Sum(Case (role) when 'Interview Room' then 1 else 0 end) as 'Interview Room'
, Sum(Case (role) when 'Sch Drop In' then 1 else 0 end) as 'Sch Drop In'
, Sum(Case (role) when 'Sch CX Staff' then 1 else 0 end) as 'Sch CX Staff'
, Sum(Case (role) when 'Not in Use' then 1 else 0 end) as 'Not in Use'
, Sum(Case (role) when 'Public' then 1 else 0 end) as 'Public'
, Sum(Case (role) when 'IAG' then 1 else 0 end) as 'IAG'
, Sum(Case (role) when 'Delivery' then 1 else 0 end) as 'Delivery'
, Sum(Case (role) when 'NVQ Use' then 1 else 0 end) as 'NVQ Use'
, Sum(Case (role) when 'Hot Swap Spare' then 1 else 0 end) as 'Hot Swap Spare'
, Sum(Case (role) when 'Archived' then 1 else 0 end) as 'Archived'
, Sum(Case (role) when 'Network Infrastructure' then 1 else 0 end) as 'Network Infrastructure'
, Sum(Case (role) when 'Unknown' then 1 else 0 end) as 'Unknown'
, Sum(Case (role) when 'Drop in Centres' then 1 else 0 end) as 'Drop in Centres'
, Sum(Case (role) when 'Training' then 1 else 0 end) as 'Training'
from tempassets2
group by office, role
order by office

any help appreciated.

View 2 Replies View Related

Compute By Clause Problem In SQL 2000

Feb 9, 2004

I am having a problem with this compute by clause

The statement is a simple select

Select col1, col2 from table1
where <where clause>
order by col1
Compute Sum(col2) by col1

I want the display to show details and group totals.

The error message I keep getting is
Server: Msg 410, Level 16, State 2, Line 1
COMPUTE clause #1 'BY' expression #1 is not in the order by list.


I have previously used the compute clause so I know it should work !!

Ay help will be appreciated - Thank you.

View 4 Replies View Related

Compute Sum Result Cannot Show In Report?

Aug 23, 2014

How to display sql compute sum command their result in amount and qty in report?

I am try this query is successful show the total amount and qty in studio management server and show in screen. But run this query on report is without to show last column of qty and amount, why ?

select
xsodetail.shopcode,xsodetail.memono,xsodetail.txdate,
xsodetail.sku,xsoheader.depositamt,xsopayment.paymentcode,xsopayment.paymentamt,
xsodetail.itemamt,xsodetail.salesqty

from xsoheader
inner join xsodetail on xsoheader.shopcode + xsoheader.memono = xsodetail.shopcode + xsodetail.memono
inner join xsopayment on xsoheader.shopcode + xsoheader.memono = xsopayment.shopcode + xsopayment.memono
where (xsodetail.sku = 'L000254' or xsodetail.sku='L000256') and xsoheader.voidflag='N' and xsodetail.txdate = CONVERT(varchar(100), GETDATE(), 112)
compute sum(xsopayment.paymentamt) , sum(xsodetail.salesqty)

View 2 Replies View Related

Compute Command Change To Rollup?

Aug 25, 2014

i want this keep query output result but don't want the "compute " this command , because this query cannot run in this dos command directc.exe , Thus, it is have any writing skill , it is possible using of rollup ?

select d.shopcode
,d.memono
,d.txdate
,d.sku
,h.depositamt

[Code] ....

View 2 Replies View Related

How To Compute For A Backup File Size

Jan 9, 2008

hello guys,

Please bare with my english.

Is there a way to compute for the backup file size of the database.
Example.

DatabaseName
TEST_DB

*in MB
DataSize DataSize_Used DataSize_UnUsed
150.00 81.00 70.00

LogSize LogSize_Used LogSize_UnUsed
30.00 1.00 29.00


When I run a backup for TEST_DB ,
*base on this figure - can we compute the the estimated backup file size for TEST_DB?

View 2 Replies View Related

Compute Parent Status From Child Statuses?

May 22, 2008

Take the example of a master-detail/parent-child set of tables, say, for example, an order table and order details. The order details table has bit field called "IsShipped". I want the overall order status to be shipped=true when all of the order details have their IsShipped column true. Let's say this is in a stored procedure that returns a result set of orders and whether or not they are completely shipped. How could I achieve this?

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved