上次没有说全消费表xf
id product_h sl
1 P001 1
2 P002 2
3 P001 3价格表jg
id product_h jg
1 P001 10
2 P001 20
3 P002 30
我想要的效果是 统计金额,表xf的数量sl*价格表的同样货号的第一个记录
select a.product_h,sum(a.sl*(select top 1 jg from jg where product_h=a.product_h)) as je
from xf a
group by a.product_h服务器: 消息 130,级别 15,状态 1,行 1
不能对包含聚合或子查询的表达式执行聚合函数。谢谢
id product_h sl
1 P001 1
2 P002 2
3 P001 3价格表jg
id product_h jg
1 P001 10
2 P001 20
3 P002 30
我想要的效果是 统计金额,表xf的数量sl*价格表的同样货号的第一个记录
select a.product_h,sum(a.sl*(select top 1 jg from jg where product_h=a.product_h)) as je
from xf a
group by a.product_h服务器: 消息 130,级别 15,状态 1,行 1
不能对包含聚合或子查询的表达式执行聚合函数。谢谢
解决方案 »
- 在重复记录中去掉第一条记录,显示其他重复记录
- 在一表中想找出最新、次新、再次新三条记录,采用什么方法方便一些啊?请前辈指点!
- 如何将当前时间取出来(不含日期)保存在一个numeric型字段中呢?日期我会存,但是纯时间我不知如何保存?
- 请问几个问题可以么,我是没分了啊~~~
- 如何在PHP中调用jdbc
- 这里的两个NOT EXIST能都换成EXIST吗?为什么?
- FOR xml 语句输出是不是有大小限制?
- 我想在Query中的params中添加一个参数,可点开params后,总是处于无效状态,请问怎办
- 求sqlserver安装包,可视化界面那种,网上的都是广告,实在不知道下哪个
- 安装sql server 2008 时报错
- 查询新疆维吾尔语显示问号?续:新问题
- sql子类递归问题求助
a.product_h,
sum(a.sl* b.jg) as je
from xf a
left join (select distinct product_h,jg from jg) b
on a.product_h = b.product_h
group by a.product_h
from xf a
group by a.product_h
from(
select a.product_h,a.sl*(select top 1 jg from jg where product_h=a.product_h) as je
from xf a )T
group by a.product_h
create table xf(id int,product_h varchar(4), sl int)
insert into xf values (1, 'P001', 1)
insert into xf values (2, 'P002', 2)
insert into xf values (3, 'P001', 3)create table jg(id int,product_h varchar(4), sl int)
insert into jg values (1, 'P001', 10)
insert into jg values (2, 'P001', 20)
insert into jg values (3, 'P002', 30)select xf.product_h,sum(xf.sl * x.sl)as je
from xf outer apply (select top 1 sl from jg where xf.product_h = jg.product_h)x
group by xf.product_h