这个语句该怎么写……

scjb79 2003-03-31 01:50:02
我要对表的F2字段求和,但求和用的记录要求是根据字段F1排除重复的结果,一条语句该怎么写呢?请大虾们指点一下
...全文
51 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ibanez550 2003-03-31
select a.f1,sum(a.f2) as f2
from (select distinct t1.f1(这儿,条件的),t2.f2 from t1 inner join t2 on t1.f1=t2.f1 and t1.f1 like 'dddd%') a
group by a.f1
你可以这样试试
回复
scjb79 2003-03-31
ibanez550运行不了,返回错误信息
"the column prefix "t1" does not match with a table name or alias name used in the query."
回复
liuyunfeidu 2003-03-31
啊,来完了。
回复
chpeng 2003-03-31
select f1,F2=sum(IsNull(F2,0)) from table group by F1
回复
ibanez550 2003-03-31
select a.f1,sum(a.f2) as f2
from (select distinct t2.f1,t2.f2 from t1 inner join t2 on t1.f1=t2.f1 and t1.f1 like 'dddd%') a
group by a.f1
按照这个思路就可以了
回复
CrazyFor 2003-03-31
TRY:
select sum (f2) from (select t1.f1,max(t2.f2) f2 from t1 inner join t2 on t1.f1=t2.f1 and t1.f1 like 'dddd%')aa
回复
scjb79 2003-03-31
谢谢各位,请再帮忙看看啊,我顶
回复
scjb79 2003-03-31
select sum (f2) from (select distinct f1,f2 from table)aa 可以了,谢谢大力兄。
不过还有个条件: t1表的f1内联到t2表的f1怎么把这两部分组和在一起呢?我试了一下
select sum (f2) from t1 inner join t2 on t1.f1=t2.f1 and t1.f1 like 'dddd%',(select distinct f1,f2 from table)aa 长时间不返回
回复
SophiaWang 2003-03-31
select sum(f2)
from
(select distinct f1,f2 from tablename)
回复
weixiao51 2003-03-31
楼上的,不行,table 里有很多重复的 f1,

select sum(f2) from (select distinct(f1), f2 from table) A
回复
benxie 2003-03-31
楼上的可以啦。
不知道这样可不可以, 你试试吧。。
select sum(f2) from table where f1 in (select distinct(f1) from table)
回复
pengdali 2003-03-31
select sum (f2) from (select f1,mix(f2) f2 from table group by F1) aa

or

select sum (f2) from (select distinct f1,f2 from table) aa
回复
CrazyFor 2003-03-31
select sum(f2) from (select f1,max(f2) f2 from table group by F1)aa
回复
comman_wang 2003-03-31
select DISTINCT f1,sum(f2) from table group by F1
采用DINSTINCT函数去除重复的记录
回复
CrazyFor 2003-03-31
TRY:
select sum (f2) from (select f1,mix(f2) f2 from table group by F1)
回复
linzhisong 2003-03-31
select f1,sum(f2) from table group by F1
回复
linzhisong 2003-03-31
select f1,sum(f2) from table group F1
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

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