由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - SQL 题目,包子有谢!
相关主题
DW developer 位置的代码在线测试考什么语言?谢谢!美东有没有老中的oralce user group呀?
15万收入怎么样请推荐菜鸟入门级Oracle参考书
【征文】Oracle Advanced PL/SQL 系列PL/SQL工作机会多吗
学习Oracle的开始喽 - SQL/PLSQL (ZZ from CINAOUG)September 8 in Reston, VA - OTN Developer Day
讲座的时间可以置顶吗?Re: [转载] JDBC用完了oracle的large pool (memor
SQL求救,helpdba interview 都问些啥
open cursor for collection?中国人北美甲骨文用户组2012年隆重推出大型IT新手入门讲座
老印给我的一个Challenge发不和谐文章--Oracle is #1 in the RDBMS Sector for 2011 (ZZ)
相关话题的讨论汇总
话题: sql话题: building1话题: room1话题: room2话题: building3
进入Database版参与讨论
1 (共1页)
j****s
发帖数: 881
1
有好几个buildings: 1, 2, 3, 4...
每个building有好几个房间A, B,C,D...
每个房间有不同的一个或好几个物品:a, b, c, d...
表格如下(3列,building,room,items):
building1 room1 a, c
building1 room2 b, c, d
building2 room3 a
building3 room1 a, d
.....
请问如何变成这种格式:
building1 room1 a
building1 room1 c
building1 room2 b
building1 room2 c
building1 room2 d
building2 room3 a
building3 room1 a
building3 room1 d
......
包子有谢!
B*****g
发帖数: 34098
2
什么数据库,什么版本?俺估计没时间写,你自己写吧。以oracle为例,基本方向有两
个。
方法1是用XML function,比如XMLTABLE;
方法2是用recursive sql/connect by,尽量用recursive sql;

【在 j****s 的大作中提到】
: 有好几个buildings: 1, 2, 3, 4...
: 每个building有好几个房间A, B,C,D...
: 每个房间有不同的一个或好几个物品:a, b, c, d...
: 表格如下(3列,building,room,items):
: building1 room1 a, c
: building1 room2 b, c, d
: building2 room3 a
: building3 room1 a, d
: .....
: 请问如何变成这种格式:

j****s
发帖数: 881
3
多谢北京,包子马上就发。
还是不太明白,我用的是SQL Server 2008。请高手多多提点。

【在 B*****g 的大作中提到】
: 什么数据库,什么版本?俺估计没时间写,你自己写吧。以oracle为例,基本方向有两
: 个。
: 方法1是用XML function,比如XMLTABLE;
: 方法2是用recursive sql/connect by,尽量用recursive sql;

B*****g
发帖数: 34098
4
同学呀,要学会使用google。俺已经说了可以用XML,你就可以google "sql server xm
l parse delimited string"。 点击第一个link, 再点两层,then congratulation, y
ou got the answer.
如果还没找到,没关系,答案link在这儿
http://beyondrelational.com/blogs/jacob/archive/2008/08/14/xque
-to-parse-a-delimited-string.aspx
http://beyondrelational.com/blogs/jacob/archive/2008/08/14/xque
-to-parse-a-delimited-string.aspx

有两

【在 j****s 的大作中提到】
: 多谢北京,包子马上就发。
: 还是不太明白,我用的是SQL Server 2008。请高手多多提点。

v***e
发帖数: 2108
5
为什么要xml? 这难道不是一个基本的PL/SQL LOOP, 定义两个cursor
一个cursor读原表,另一个insert新表
对原表每个row,parse Col items, 然后一个nested loop
用第二个cursor insert 到新表去?

xm
y

【在 B*****g 的大作中提到】
: 同学呀,要学会使用google。俺已经说了可以用XML,你就可以google "sql server xm
: l parse delimited string"。 点击第一个link, 再点两层,then congratulation, y
: ou got the answer.
: 如果还没找到,没关系,答案link在这儿
: http://beyondrelational.com/blogs/jacob/archive/2008/08/14/xque
: -to-parse-a-delimited-string.aspx
: http://beyondrelational.com/blogs/jacob/archive/2008/08/14/xque
: -to-parse-a-delimited-string.aspx
:
: 有两

a9
发帖数: 21638
6
慢。

server
congratulation,

【在 v***e 的大作中提到】
: 为什么要xml? 这难道不是一个基本的PL/SQL LOOP, 定义两个cursor
: 一个cursor读原表,另一个insert新表
: 对原表每个row,parse Col items, 然后一个nested loop
: 用第二个cursor insert 到新表去?
:
: xm
: y

B*****g
发帖数: 34098
7
如果人家问SQL,你就答SQL,答不出来再用PLSQL。俺N年前面试就是这样做的
~~~~~~~~~~~~~`
Tom Kyte’s:
You should do it in a single SQL statement if at all possible.
If you cannot do it in a single SQL Statement, then do it in PL/SQL.
If you cannot do it in PL/SQL, try a Java Stored Procedure.
If you cannot do it in Java, do it in a C external procedure.
If you cannot do it in a C external routine, you might want to seriously
think about why it is you need to do it…
Beijing:
一些问题developer不用SQL不是因为SP更好,而是因为developer写不出SQL
~~~~~~~~~~~~~~~

【在 v***e 的大作中提到】
: 为什么要xml? 这难道不是一个基本的PL/SQL LOOP, 定义两个cursor
: 一个cursor读原表,另一个insert新表
: 对原表每个row,parse Col items, 然后一个nested loop
: 用第二个cursor insert 到新表去?
:
: xm
: y

v***e
发帖数: 2108
8
我觉得这种说法在以前是可以理解,但是现在未必是这样
interview倒也罢了,但是如果是实际工作,XML这种东西一
定比pl/sql快么? 好像很难说吧。
写一个SQL statment并不能简化solution的内在逻辑,只是把所有
东西压缩在一个stmt里面了。
而且即使是写一个巨大,复杂,难以维护的single SQL statement,
也未必一定比一个简单,逻辑清晰的compiled pl/sql function
更efficient,其中一个原因是一旦你SQL stmt复杂之后,plan
generation 和plan execution都很难做到opitimized。而且复杂的sql
像cursor sharing,result cache这种feature就更难运用。
从RDBMS内核的角度看,我个人不太赞成把任何东西都写在一个SQL里面。

【在 B*****g 的大作中提到】
: 如果人家问SQL,你就答SQL,答不出来再用PLSQL。俺N年前面试就是这样做的
: ~~~~~~~~~~~~~`
: Tom Kyte’s:
: You should do it in a single SQL statement if at all possible.
: If you cannot do it in a single SQL Statement, then do it in PL/SQL.
: If you cannot do it in PL/SQL, try a Java Stored Procedure.
: If you cannot do it in Java, do it in a C external procedure.
: If you cannot do it in a C external routine, you might want to seriously
: think about why it is you need to do it…
: Beijing:

B*****g
发帖数: 34098
9
我要厚道
j****s
发帖数: 881
10
多谢verde,至少我大概看明白了。包子感谢。
北京姐姐真高深,菜鸟仰慕了。。。
不知还有没有别的方法。
B*****g
发帖数: 34098
11
到CINAOUG,里面大牛很多,而且SQL Server的系列活动就要开始了

【在 j****s 的大作中提到】
: 多谢verde,至少我大概看明白了。包子感谢。
: 北京姐姐真高深,菜鸟仰慕了。。。
: 不知还有没有别的方法。

j****s
发帖数: 881
12
请问北京怎么申请加入CINAOUG?很想参加SQL Server的系列活动提高自己,是不是
webinar形式呢?
多谢!
B*****g
发帖数: 34098
13
Chinese in North America Oracle User Group (CINAOUG)
http://groups.google.com/group/cinaoug
有webinar,还有些列文章(反映好就加上系列讲座)

【在 j****s 的大作中提到】
: 请问北京怎么申请加入CINAOUG?很想参加SQL Server的系列活动提高自己,是不是
: webinar形式呢?
: 多谢!

j****s
发帖数: 881
14
Thank you Beijing! Just sent the application.
1 (共1页)
进入Database版参与讨论
相关主题
发不和谐文章--Oracle is #1 in the RDBMS Sector for 2011 (ZZ)讲座的时间可以置顶吗?
[转载] a PLSQL questionSQL求救,help
这两个 xml db 有什么不同?open cursor for collection?
Oracle SQL Tunning Problem!老印给我的一个Challenge
DW developer 位置的代码在线测试考什么语言?谢谢!美东有没有老中的oralce user group呀?
15万收入怎么样请推荐菜鸟入门级Oracle参考书
【征文】Oracle Advanced PL/SQL 系列PL/SQL工作机会多吗
学习Oracle的开始喽 - SQL/PLSQL (ZZ from CINAOUG)September 8 in Reston, VA - OTN Developer Day
相关话题的讨论汇总
话题: sql话题: building1话题: room1话题: room2话题: building3