帮忙写个SQL语句

jianghua008 2003-04-07 08:01:43
sales:
comcode sales
a 5
a 6
b 7
b 8

companyinfo:
comcode name
a sz
b gz

要求输出:
name avgsales
sz 6.5
gz 7.5
...全文
8 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
gawz 2003-04-08
具體的思路是什麼啊...什麼聯繫啊
回复
benxie 2003-04-07
select name,avg(sales) from sales a,companyinfo b where a.comcode=b.comcode
group by name
回复
luckhua 2003-04-07
SELECT companyinfo.name,sales.sales
FROM companyinfo
LEFT JOIN
(SELECT comcode,AVG(sales)AS sales
FROM sales
GROUP BY comcode
) AS
sales ON sales.comcode=companyinfo.comcode
回复
pengdali 2003-04-07
如果是要

name avgsales
sz 5.5
gz 7.5

的话:

select b.name,cast(avg(a.sales+0.0) as numeric
(10,1) from sales a,companyinfo b where a.comcode=b.comcode
group by name
回复
pengdali 2003-04-07
题目有问题吗?看不出有联系呀!
回复
spland 2003-04-07
select name,avg(sales) from
sales left join companyinfo on sales.comcode = companyinfo.comcode
group by name sales.comcode
回复
caiyunxia 2003-04-07
select name,avg(sales) from
sales a,companyinfo b where a.comcode=b.comcode
group by name
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-07 08:01
社区公告
暂无公告