Sql query for tree table

Expanding on a_horse_with_no_name’s answer, this show how to use SQL Server’s implementation of recursive CTE (recursive single-record cross apply) in combination with row_number() to produce the exact output in the question. declare @t table(id int,parentId int,name varchar(20)) insert @t select 1, 0 ,’Category1′ insert @t select 2, 0, ‘Category2’ insert @t select 3, 1, ‘Category3’ … Read more

MySQL Closure Table hierarchical database – How to pull information out in the correct order

SELECT d.`iD`, d.`subsectionOf`, CONCAT(REPEAT(‘-‘, p.`len`), d.`name`) as hier, p.`len`, p.`ancestor`, p.`descendant`, GROUP_CONCAT(crumbs.`ancestor`) AS breadcrumbs FROM `TreeData` AS d JOIN `TreePaths` AS p ON d.`iD` = p.`descendant` JOIN `TreePaths` AS crumbs ON crumbs.`descendant` = p.`descendant` WHERE p.`ancestor` = 1 GROUP BY d.`iD` ORDER BY breadcrumbs; +—-+————–+———————+—–+———-+————+————-+ | iD | subsectionOf | hier | len | ancestor … Read more

Expressing recursion in LINQ

Linq-toXml handles this fine, there is an XElement.Elements()/.Nodes() operation to get immediate children, and a XElement.Descendents()/DescendentNodes() operations to get all descendents. Would you consider that as an example? To summarize Linq-to-Xml’s behavior… The navigation functions each correspond to an axis type in XPath (http://www.w3schools.com/xpath/xpath_axes.asp). If the navigation function selects Elements, the axis name is used. … Read more

WPF Treeview Databinding Hierarchal Data with mixed types

Since you want the elements in the TreeView to have a list of children that consists of both Categories Products, you will want your Category ViewModel to have a collection that consists of both Categories and Products. For example, you could use a CompositeCollection to combine your existing collections: public class Category { public string … Read more

Resampling Within a Pandas MultiIndex

pd.Grouper allows you to specify a “groupby instruction for a target object”. In particular, you can use it to group by dates even if df.index is not a DatetimeIndex: df.groupby(pd.Grouper(freq=’2D’, level=-1)) The level=-1 tells pd.Grouper to look for the dates in the last level of the MultiIndex. Moreover, you can use this in conjunction with … Read more