免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3843 | 回复: 7
打印 上一主题 下一主题

子查询的款困惑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-15 20:56 |只看该作者 |倒序浏览
本帖最后由 zhaoyh603 于 2011-02-15 21:47 编辑

select  (select a.dept_fullname from ad_department a where a.dept_id = parent_id)||'_'||dept_name as b ,dept_name,parent_id  from ad_department
Where Length(dept_Code) = 6    And dept_Code Like '99%' ;

b是空的

select b.dept_fullname||'_'||a.dept_name as b , a.dept_name from  ad_department a,ad_department b where a.parent_id=b.dept_id;

可以

目的是想update dept_fullname

为什么呀 疑惑

论坛徽章:
0
2 [报告]
发表于 2011-02-15 21:16 |只看该作者
本帖最后由 zhaoyh603 于 2011-02-15 21:47 编辑

select  (select a.dept_fullname from ad_department a where a.dept_id = b.parent_id)||'_'||b.dept_name as b ,b.dept_name,b.parent_id  from ad_department b
Where Length(b.dept_Code) = 6    And b.dept_Code Like '99%' ;

加了别名就可以了,晕 why

论坛徽章:
0
3 [报告]
发表于 2011-02-15 21:23 |只看该作者
本帖最后由 zhaoyh603 于 2011-02-15 21:48 编辑

update ad_department as b
set b.dept_fullname=(select a.dept_fullname from ad_department a where a.dept_id = b.parent_id)||'_'||b.dept_name
Where Length(b.dept_Code) = 6    And b.dept_Code Like '99%' ;

错误:
ERROR:  column "b" of relation "ad_department" does not exist
LINE 2: set b.dept_fullname=(select a.dept_fullname from ad_departme...

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
4 [报告]
发表于 2011-02-15 21:30 |只看该作者
晕呼,没看明白。

论坛徽章:
0
5 [报告]
发表于 2011-02-15 21:33 |只看该作者
本帖最后由 zhaoyh603 于 2011-02-15 21:48 编辑

update ad_department b
set dept_fullname=a.dept_fullname||'_'||b.dept_name
from ad_department as a
Where Length(b.dept_Code) = 6    And b.dept_Code Like '99%'  and a.dept_id = b.parent_id;

这样可以

oracle这样貌似不行吧

什么标准?

论坛徽章:
0
6 [报告]
发表于 2011-02-15 21:49 |只看该作者
看明白了吗?

论坛徽章:
0
7 [报告]
发表于 2011-02-16 15:41 |只看该作者
语法是有差别,习惯了就好。
postgresql的语法更易理解。

5楼的语法可以这样理解:两表先join后,再更新,反之3楼的语法,更难于理解。

论坛徽章:
0
8 [报告]
发表于 2011-02-17 20:52 |只看该作者
恩,是有差别,可是将来移植起来就麻烦啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP