我有两张表:Table 1: ID     name   Type     group     conditionID
----------------------------------------------------
       1      temp1  日志     group1    condition1
                                      condition2
                                      condition3
----------------------------------------------------
      2      temp2  日志     group2    condition4
                                      condition2
                                      condition1
-----------------------------------------------------
      3      temp3  日志     group1    condition5
                                      condition6
                                      condition3
----------------------------------------------------
Table 2   conditionID   description
------------------------------------
      condition1     log 
--------------------------------
      condition2     montioner
---------------------------------
      condition3     message
--------------------------------
      condition4    application
----------------------------------我用sql语句做查询,想要得到的结果如下:(就是把condition和它的描述,作为其中的两个子行输出),样子如下:
select ....from table1,table2: 
       1      temp1  日志     group1    condition1  log
                                      condition2  montioner
                                      condition3  message

----------------------------------------------------
      2      temp2  日志     group2    condition4  
                                      condition2
                                      condition1

-----------------------------------------------------
      3      temp3  日志     group1    condition5
                                      condition6
                                      condition3
在一个大的行下面,在包含几个子行,用来描述每个condition.万分感谢!
                                     

解决方案 »

  1.   

    上面的格式有点串行,请参考这个。  
    Table 1: ID    name  Type    group    conditionID 
    ---------------------------------------------------- 
          1      temp1  日志    group1    condition1 
                                          condition2 
                                          condition3 
    ---------------------------------------------------- 
          2      temp2  日志    group2    condition4 
                                          condition2 
                                          condition1 
    ----------------------------------------------------- 
          3      temp3  日志    group1    condition5 
                                          condition6 
                                          condition3 
    ---------------------------------------------------- 
    Table 2  conditionID  description 
    ------------------------------------ 
          condition1    log 
    -------------------------------- 
          condition2    montioner 
    --------------------------------- 
          condition3    message 
    -------------------------------- 
          condition4    application 
    ---------------------------------- 我用sql语句做查询,想要得到的结果如下:(就是把condition和它的描述,作为其中的两个子行输出),样子如下: 
    select ....from table1,table2: 
          1      temp1  日志    group1    condition1  log 
                                          condition2  montioner 
                                          condition3  message 
    ---------------------------------------------------- 
          2      temp2  日志    group2    condition4  
                                          condition2 
                                          condition1 
    ----------------------------------------------------- 
          3      temp3  日志    group1    condition5 
                                          condition6 
                                          condition3 在一个大的行下面,在包含几个子行,用来描述每个condition. 万分感谢! 
      

  2.   

    还是有点乱,就是condition 都是在一列里面。
      

  3.   

    你的意思是TABLE1的每个
          1      temp1  日志    group1    condition1
                                          condition2
                                          condition3    
    这其实是数据库里的一行一列是吧,如果这样的话,你的conditionID 数据有什么明显的特征没有,ORACLE好像
    不能在一个单元格数据里换行显示的,如果每个conditionID可以按某个规则分割的,你就分割开然后挨个关联
    TABLE2,接着在合并就是你要的结果了
      

  4.   

    这table1的结构诡异啊...
    conditionid是不是在一行里?
      

  5.   

    lz想要这样的结果吧,帮你编辑了下
    Table 1: ID    name  Type    group    conditionID 
    ---------------------------------------------------- 
              1    temp1  日志    group1    condition1 
                                           condition2 
                                           condition3 
    ---------------------------------------------------- 
              2    temp2  日志    group2    condition4 
                                           condition2 
                                           condition1 
    ----------------------------------------------------- 
              3    temp3  日志    group1    condition5 
                                           condition6 
                                           condition3 
    ---------------------------------------------------- 
    Table 2  conditionID  description 
    ------------------------------------ 
               condition1    log 
    -------------------------------- 
               condition2    montioner 
    --------------------------------- 
               condition3    message 
    -------------------------------- 
               condition4    application 
    ---------------------------------- --我用sql语句做查询,想要得到的结果如下:(就是把condition和它的描述,作为其中的两个子行输出),样子如下: 
    --select ....from table1,table2: 
          1      temp1  日志    group1    condition1  log 
                                         condition2  montioner 
                                         condition3  message 
    ---------------------------------------------------- 
          2      temp2  日志    group2    condition4  
                                         condition2 
                                         condition1 
    ----------------------------------------------------- 
          3      temp3  日志    group1    condition5 
                                         condition6 
                                         condition3 
      

  6.   

    是这样?
    select a.ID,a.name,a.Type,a.group,a.conditionID,b.description 
    from table1 a,table2 b
    where a.conditionID=b.conditionID
      

  7.   

    lz一定要把每组内的id,name只显示一次吗,还是每条都显示也可以
    后者的话就是7楼的答案了
      

  8.   

    table1里的conditionID是怎么存储,一条记录怎么会换行啊?
      

  9.   

    select (case when id=id1 then id else null end) id,name,type,group,conditionID,description 
    from (select a.ID,lag(a.id,1,0) over(order by id) id1,a.name,a.Type,a.group,a.conditionID,b.description 
    from table1 a,table2 b
    where a.conditionID=b.conditionID)
    order by id;
      

  10.   

    select (case when id=id1 then id else null end) id,
    (case when id=id1 then name else null end) name,
    (case when id=id1 then type else null end) type,
    (case when id=id1 then group else null end) group,conditionID,description 
    from (select a.ID,lag(a.id,1,0) over(order by id) id1,a.name,a.Type,a.group,a.conditionID,b.description 
    from table1 a,table2 b
    where a.conditionID=b.conditionID)
    order by id;
      

  11.   

    lz你主要是想在页面显示出这样的效果是吧,如果是的话,还除了这样的效果还有一个方式可以解决。
    GridView嵌套就可以了