SQL语句建立视图,涉及到两个表
我有这样两张表想建立一个视图,在member表后边加两列第一列显示第二张表中相同名字的总和添加到对应的名字后,第二列显示第一张表中initpoint+addpoint+a...
我有这样两张表 想建立一个视图,在member表后边加两列 第一列显示第二张表中相同名字的总和添加到对应的名字后,第二列显示第一张表中initpoint+addpoint+adj-刚才新加那列的结果求怎么破,好像挺麻烦的 研究了好久也没弄明白
sqlitebrowser-1.3 展开
sqlitebrowser-1.3 展开
2个回答
2013-11-11
展开全部
create view V_member as
select * from (select
a.memberid,a.membername,a.vocation,a.initpoint,a.addpoint,a.adj,a.remark,
--第一列
b.dkp,
--第二列
(a.initpoint+a.addpoint+a.adj-b.dkp)as dkp2 from member a
left join
--计算第二张表的相同名称人员的dkp总和
(select membername,sum(dkp)as dkp from expense group by membername) b on a.menbername=b.membername)tbl
select * from (select
a.memberid,a.membername,a.vocation,a.initpoint,a.addpoint,a.adj,a.remark,
--第一列
b.dkp,
--第二列
(a.initpoint+a.addpoint+a.adj-b.dkp)as dkp2 from member a
left join
--计算第二张表的相同名称人员的dkp总和
(select membername,sum(dkp)as dkp from expense group by membername) b on a.menbername=b.membername)tbl
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create view vw_member
as
select a.memberid,a.membername,a.vocation,a.initpoint,a.addpoint,a.adj,a.remark,b.dkp, (a.initpoint+a.addpoint+a.adj-b.dkp)as dkp2 from member a
left join (select membername,sum(dkp)as dkp from expense group by membername)as b
on a.menbername=b.membername
as
select a.memberid,a.membername,a.vocation,a.initpoint,a.addpoint,a.adj,a.remark,b.dkp, (a.initpoint+a.addpoint+a.adj-b.dkp)as dkp2 from member a
left join (select membername,sum(dkp)as dkp from expense group by membername)as b
on a.menbername=b.membername
更多追问追答
追问
Error: no such column: a.menbername
亲 这是什么情况?
追答
打错一个字
最后一句应该是on a.membername=b.membername
哈 楼下的抄我的回答哦 错的地方也一模一样 只不过加上了注解 这有点不厚道哎
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询