怎么样写才能得到图2 的子项 大区经理  RPM 大区助理  
如果 字段 Residential 有重复  只显示一次。。
谢谢大家!

解决方案 »

  1.   

    去除重复字段?
    这- -
    distinct 
      

  2.   

    select *
    from tb t
    where id = (select max(id) from tb where Residential = t.Residential )
    and
    Largearea='LD-北京'
      

  3.   

    前台页面采用控件嵌套<asp:Repeater ID="rptLarge" runat="server">
        <ItemTemplate>
            <div><input type="checkbox" /><%#Eval("LargeArea") %></div>
            <div>
                <asp:Repeater ID="rptSmall" runat="server">
                    <ItemTemplate>
                        <input type="checkbox" /><%#Eval("Residential")%>
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    数据查询分两步:
    1.先查询出所有大区SELECT [LargeArea] From 表 GROUP BY [LargeArea]
    2.根据大区选出小区SELECT DISTINCT [Residential] FROM 表 WHERE [LargeArea] = 大区
    数据库中没有保存区域的表吗?若没有,设计上就有问题了...
      

  4.   

    用group by行不?那样子的话就可以不显示重复内容了
      

  5.   


    --不会啊 LD-北京的都有显示出来
    create table #temp(id int,Residential varchar(50),Largearea varchar(50))
    insert into #temp
    select 1,'大区经理','LD-北京' union all
    select 2,'RPM'     ,'LD-北京' union all
    select 3,'大区经理','LD-北京' union all
    select 4,'北京EN-1','LD-北京' union all
    select 5,'北京EN-2','LD-北京' union all
    select 5,'沈阳LE-1','LD-北区' union all
    select 6,'北京LE'  ,'LD-北京'select * from #temp t where id=(select max(id) from #temp where Residential=t.Residential) and Largearea='LD-北京'
    /*
    2 RPM LD-北京
    3 大区经理 LD-北京
    4 北京EN-1 LD-北京
    5 北京EN-2 LD-北京
    6 北京LE LD-北京
    */
      

  6.   

    select  Residential from tb where largearea="LD_北京" group by Residential;
      

  7.   


    如果没有可以用Distinct把所有区别查出来,从第二图上可以看到那是明显的group by
      

  8.   


    您这样只显示了第一条和最后一条 图片是查询出来的结果。
    表里实际北京LE北京EN-2大区助理 大区经理 等字段 这个字段要是有重复的只显示一次。这才是我要的
      

  9.   


    您这样只查询了两个字段 。我要全部   根据这个字段来查询出 Residential 但是Residential重复的只显示一次
      

  10.   


    我把  max  换成了 min   可以了 谢谢您!
      

  11.   

    有JQuery吧  我做过类似的权限管理
      

  12.   

     select * from #temp t where residential=(select distinct Residential from #temp where Residential=t.Residential) and Largearea='LD-北京'
    试一试这个。
      

  13.   

    强烈建议将cPost和Residential这两个字段分离出来,单独形成用户角色表和区域划分表,这样直接利用索引就可以去查询了。