各位大侠帮小妹看看这个sql语句错在哪里,很急啊?

lindentree 2003-12-03 10:50:43
有表A, B,A中存放的是基本信息,B中存放的是数据,它们用编码连接也就是
(A.material_code = B.g_code)连接,现在我要取出B.g_tuinum的总数,B.loan的总数,以及B.g_tuinum每个记录的B.g_tuinum与之对应的单价想乘再求总金额,同样B.g_loan也以相同的方法求总金额,不晓得这个出错在哪里。

各位大侠帮忙指点一下。

select sum(B.g_tuinum) as totalin, sum(B.loan) as totalout, sum(A.material_price * B.g_tuinum) as totalinprice, sum(A.material_code * B.g_loan) as totaloutprice from tb_material A, "&tablename&" B where (A.material_code = B.g_code) and (B.g_date = '"&Sdate&"') and (B.g_tuinum > 0 or B.g_loan >0)
...全文
67 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzq686 2003-12-03
  • 打赏
  • 举报
回复
客气!都是兄弟 在这!
lindentree 2003-12-03
  • 打赏
  • 举报
回复
哎呀,真的是我自己马虎写错了,谢谢,
谢谢各位,谢谢xzq686(瞬)
onebody 2003-12-03
  • 打赏
  • 举报
回复
up
xzq686 2003-12-03
  • 打赏
  • 举报
回复
我在查询分析器中试了一上,可以。你试试。
xzq686 2003-12-03
  • 打赏
  • 举报
回复
我打错了,是sum(B.g_loan) ,不是sum(b.loan) ,少了一个"g_"
xzq686 2003-12-03
  • 打赏
  • 举报
回复
你的一个字段出错了。是sum(B.g_loan) ,不是sum(g_loan) ,少了一个B.
select sum(B.g_tuinum) as totalin, sum(B.g_loan) as totalout, sum(A.material_price * B.g_tuinum) as totalinprice, sum(A.material_code * B.g_loan) as totaloutprice from tb_material A, "&tablename&" where (A.material_code = B.g_code) and (B.g_date = '"&Sdate&"') and (B.g_tuinum > 0 or B.g_loan >0)
cgq210 2003-12-03
  • 打赏
  • 举报
回复
你应该把(select g_code,sum(g_tuinum),sum(g_loan) from B group by g_code)当成你原来句子里的B表来做就分解成了一个简单的查询语句了!
cgq210 2003-12-03
  • 打赏
  • 举报
回复
有出错信息吗?
xxrl 2003-12-03
  • 打赏
  • 举报
回复
用视图或许更简单一点!
lindentree 2003-12-03
  • 打赏
  • 举报
回复
怎么没有人回答呢??
或者可能是我写错了,有没有其他的方法实现呢??

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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