我有两张表: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 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.万分感谢!
解决方案 »
- oracle 文章内容检索
- ——用户A下的数据表,如何全部放到用户B下面去???——
- 获取同一个transaction中的所有SQL
- OracleOraDb11g_home1TNSListener
- ora817建立ora734上的表的同义词
- 向SQL高手请教--要实现这样的查询功能SQL语句该怎样写?
- 网络状况正常,从外网访问Oracle数据库服务总是超时,原因何在?急!
- exp命令出错,请高手赐教?
- 急啊,SQL要得到这样的结果?
- 有关临时表问题(请帮忙从一个SQLServer 2000的一个语句改到Oracle中来)
- 10G,由于下列错误,OracleOraDb10g_home1iSQL*Plus 服务启动失败:网上的办法都不行!
- 外键的选择问题
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 temp1 日志 group1 condition1
condition2
condition3
这其实是数据库里的一行一列是吧,如果这样的话,你的conditionID 数据有什么明显的特征没有,ORACLE好像
不能在一个单元格数据里换行显示的,如果每个conditionID可以按某个规则分割的,你就分割开然后挨个关联
TABLE2,接着在合并就是你要的结果了
conditionid是不是在一行里?
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
select a.ID,a.name,a.Type,a.group,a.conditionID,b.description
from table1 a,table2 b
where a.conditionID=b.conditionID
后者的话就是7楼的答案了
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;
(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;
GridView嵌套就可以了