【问题标题】:How to view another data in the same column using webgrid如何使用 webgrid 查看同一列中的另一个数据
【发布时间】:2015-10-03 22:53:33
【问题描述】:

我的表中有 3 列,分别是:
ID、姓名、父部门

ParentDepartment 的值是列 ID 中的一个 ID。例如:

ID : 1,2,3

Name : Finance, Product and Services, IT Support

ParentDepartment : 1, 2, 2

这意味着 ID 1 具有父部门“财务”,ID 2 和 3 具有父部门“产品和服务”。

我的问题是如何在WebGrid 列中显示基于 ParentDepartment 的部门名称?所以结果将是:

ID : 1, 2, 3

Name :  Finance, Product and Services, IT Support

ParentDepartment : Finance, Product and Services, Product and Services

请你帮忙。

【问题讨论】:

    标签: asp.net-mvc-4 webgrid


    【解决方案1】:

    您可以使用inner join 获得这样的结果。

    SELECT t1.ID, t1.Name as Name, t2.Name AS ParentDepartment 
    FROM myTable t1
    INNER JOIN myTable t2
    ON t1.ParentDepartment = t2.ID
    

    但是很奇怪Finance部门的上级部门是Finance部门。

    这里是SQL Fiddle Snippet

    【讨论】:

    • 如何在 WebGrid 中使用它?
    • @SunlikeSiagian 我的错:(我认为这是一个 SQL 问题。我将编辑我的问题以回答您的问题或简而言之将其删除。
    • 谢谢耶尔达。我了解 sql 内连接,但我想在“WebGrid”中使用它。这是我的代码:grid.Column("Parent Department", "????")); ??? => 我不知道如何在“WebGrid”中加入他们
    猜你喜欢
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多