关于数据库中改名字的问题

xishuinabian 2010-11-29 10:06:08
select loan.*,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number
as lb(loan_number,branch,amount,cust,cust_loan_num)


这个代码最后的一句使用as子句重新命名连接的结果关系,可是编译的时候却出现了错误,这是怎么回事啊
大家帮我看看吧
...全文
152 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
yesyesyes 2010-12-02
  • 打赏
  • 举报
回复
可以的那个用的是子查询,你的那个不是
yesyesyes 2010-12-02
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 xishuinabian 的回复:]
今天看到了一个例子,感觉和我的有点像啊
为什么这个好使了
select branch_name, avg_balance
from (select branch_name, avg(balance)
from accout
group by branch_name)
as branch_avg(branch_name, avg_balance)……
[/Quote]

这个确实可以
xishuinabian 2010-12-02
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 yesyesyes 的回复:]
[Quote=引用 14 楼 xishuinabian 的回复:]
今天看到了一个例子,感觉和我的有点像啊
为什么这个好使了
select branch_name, avg_balance
from (select branch_name, avg(balance)
from accout
group by branch_name)
as b……
[/Quote]

这个既然可以,那我那个怎么就不可以啊,有什么区别啊
yuzhongrong123 2010-12-01
  • 打赏
  • 举报
回复
语法错误 as后面的东西不能要 如果要为选出的属性列重命名的花 在选出的属性列后面 as+随便一个名字

select loan.* as 什么,borrower.* as 什么 或者去掉as 也可以的



xishuinabian 2010-12-01
  • 打赏
  • 举报
回复
今天看到了一个例子,感觉和我的有点像啊
为什么这个好使了
select branch_name, avg_balance
from (select branch_name, avg(balance)
from accout
group by branch_name)
as branch_avg(branch_name, avg_balance)
cxmcxm 2010-11-30
  • 打赏
  • 举报
回复
sql不能那样写。
abuying 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xishuinabian 的回复:]

引用 5 楼 wxf163 的回复:
不能 只能在SELECT s AS F FROM TABLE 这么弄别名

我是在一本书里看到这个例子的,还是挺有名的的一本国外的书,不会吧
[/Quote]
LZ记得不全
要么是公共表达式,要么是函数返回表值,要么是视图定义
如公共表达式如9L,10L所示
sych888 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 yesyesyes 的回复:]
或者用cte

with lb(loan_number,branch,amount,cust,cust_loan_num)
as
(select loan.*,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number)
select * from lb
[/Quote]
up.............
feilniu 2010-11-30
  • 打赏
  • 举报
回复
with lb(loan_number,branch,amount,cust,cust_loan_num) as
(
select loan.*,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number
)
SELECT * FROM lb

SQL Server 2005以上支持。

yesyesyes 2010-11-30
  • 打赏
  • 举报
回复
或者用cte

with lb(loan_number,branch,amount,cust,cust_loan_num)
as
(select loan.*,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number)
select * from lb
xishuinabian 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wxf163 的回复:]
不能 只能在SELECT s AS F FROM TABLE 这么弄别名
[/Quote]
我是在一本书里看到这个例子的,还是挺有名的的一本国外的书,不会吧
yesyesyes 2010-11-30
  • 打赏
  • 举报
回复
建视图时有类似的写法
试试
create view lb(loan_number,branch,amount,cust,cust_loan_num)
as
select loan.*,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number
xishuinabian 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 abuying 的回复:]
引用 8 楼 xishuinabian 的回复:

引用 5 楼 wxf163 的回复:
不能 只能在SELECT s AS F FROM TABLE 这么弄别名

我是在一本书里看到这个例子的,还是挺有名的的一本国外的书,不会吧

LZ记得不全
要么是公共表达式,要么是函数返回表值,要么是视图定义
如公共表达式如9L,10L所示
[/Quote]


应该是公共表达式,但是我装的2000版的试不了,上火啊
我的那个例子只写了两行代码
loan inner join borrower on loan.loan_number=borrower.loan_number
as lb(loan_number,branch,amount,cust,cust_loan_num_)
这个例子实例了如何用As子句重新命名连接结果关系以及该结果关系的属性(书上的原话)
王向飞 2010-11-29
  • 打赏
  • 举报
回复
不能 只能在SELECT s AS F FROM TABLE 这么弄别名
xishuinabian 2010-11-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 rucypli 的回复:]
select loan.col1 as xxx,loan.col2 as xxxx,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number
[/Quote]

难道不能用我那种方式吗
claro 2010-11-29
  • 打赏
  • 举报
回复
MSSQL ?
rucypli 2010-11-29
  • 打赏
  • 举报
回复
select loan.col1 as xxx,loan.col2 as xxxx,borrower.*
from loan inner join borrower on loan.loan_number=borrower.loan_number
华夏小卒 2010-11-29
  • 打赏
  • 举报
回复
select a as colnew from ta

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧