【问题标题】:sql query to get data for Spacetree (jit)用于获取 Spacetree 数据的 sql 查询(jit)
【发布时间】:2013-11-08 03:13:53
【问题描述】:

我有一个表“BinaryTree”,它有 2 列“CustomerID”和“ParentID”。

另一个表是“客户”,它有“客户ID”和“名字”列。

我想从这些表中查询数据,并希望将这些数据以Json格式分配给Spacetree。

请参考以下链接:-

http://philogb.github.io/jit/static/v20/Jit/Examples/Spacetree/example1.code.html

http://philogb.github.io/jit/static/v20/Jit/Examples/Spacetree/example1.html

我想要如下数据:-

Parentid  CustomerID  FirstName
   1          34         Test1
   1          64         Test2
   1          46         Test3
   34         45         Test4
   34         102        Test5
   64         22         Test6
   46         54         Test7

所以我可以构建 json 字符串并将其分配给 spacetree。 如果它按顺序返回数据我会很好,这意味着对于 parentid 它首先返回其所有孩子。

然后它会一一返回这些子节点的子节点,因此很容易以 spacetree 所需的正确格式构建 json 字符串。

如果需要更多信息,请告诉我。

提前谢谢各位。

【问题讨论】:

    标签: sql-server infovis thejit space-tree


    【解决方案1】:

    使用内连接。

    select BT.PARID,BT.CUSTID,CU.firstname 
    from BinaryTree BT INNER JOIN Customers CU on BT.CUSTID=CU.CUSTID
    ORDER BY BT.PARID,BT.CUSTID
    

    查看演示:http://sqlfiddle.com/#!3/1ffc1/1

    【讨论】:

    • 谢谢@Vijay,它给出的结果如下evernote.com/shard/s364/sh/3ca8dee4-8157-4531-87b9-fb910df6709c/…,因为parentid 1有2个customerid(意味着2个孩子),所以它的第一个customerid是3,所以我想要第7行和第8行就在第 4 行和第 5 行和第 6 行的下方,就在 parentid 3 的下方。希望您能提供帮助。
    • @AnandMeena:更新了答案,按顺序添加 custid
    猜你喜欢
    • 2018-11-09
    • 1970-01-01
    • 2012-07-01
    • 2013-10-08
    • 2012-10-31
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多