这句SQL错在哪

yaomin65 2009-03-20 04:05:56
我想做一个统计,发现在一张表中统计没问题,但从两张表中统计时却发现统计有问题,请高人指点一下

A) select strcd,sum(amt) from stramt where date>'1-3月-2009' group by strcd
B) select a.strcd,sum(b.amt) from strinfo a,stramt b where date>'1-3月-2009' group by a.strcd

A统计时没问题,B统计时发现sum(b.amt)全是一样的数据543564.85,为什么啊
...全文
129 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaomin65 2009-03-27
  • 打赏
  • 举报
回复
我想将大于500的列出来:
select a.strcd,sum(b.amt) from strinfo a,stramt b where a.strcd=b.strcd and b.date>'1-3月-2009' and sum(b.amt)>500 group by a.strcd
提示此处不允许使用分组函数,该怎么做啊
xixihaha_2011_098 2009-03-20
  • 打赏
  • 举报
回复
路过
clear_zero 2009-03-20
  • 打赏
  • 举报
回复
你的两张表需要有效地连接起来

select a.strcd,sum(b.amt) as tmp from strinfo a,stramt b where a.strcd=b.strcd and a.[date]>'1-3月-2009' group by a.strcd
yaomin65 2009-03-20
  • 打赏
  • 举报
回复
呵呵,加了a.strcd=b.strcd 后,只列出了B表中的strcd数据,而A表中的strcd是全部的
饮水需思源 2009-03-20
  • 打赏
  • 举报
回复
select a.strcd,sum(b.amt) as tmp from strinfo a,stramt b where a.strcd=b.strcd and a.[date]>'1-3月-2009' group by a.strcd
zlzfc 2009-03-20
  • 打赏
  • 举报
回复
[Quote=引用楼主 yaomin65 的帖子:]
我想做一个统计,发现在一张表中统计没问题,但从两张表中统计时却发现统计有问题,请高人指点一下

A) select strcd,sum(amt) from stramt where date>'1-3月-2009' group by strcd
B) select a.strcd,sum(b.amt) from strinfo a,stramt b where date>'1-3月-2009' group by a.strcd

A统计时没问题,B统计时发现sum(b.amt)全是一样的数据543564.85,为什么啊
[/Quote]
where后面 是不是要再加个限制 and a.strcd=b.strcd

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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