设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
楼主: laomms
打印 上一主题 下一主题

[Access本身] access求和

[复制链接]
1#
发表于 2014-1-16 19:02:54 | 显示全部楼层
这个有意思,研究一下。
2#
发表于 2014-1-16 19:32:29 | 显示全部楼层
laomms 发表于 2014-1-16 19:16
假如不是三单的合计,而是某一客户的全部合计等于5000,然后列出构成这5000的所有这个客户的单号,这样应该 ...

假如出来3个符合条件的结果,你们怎么办,打电话确认吗?
3#
发表于 2014-1-16 20:09:17 | 显示全部楼层
laomms 发表于 2014-1-16 19:34
是的,实际数据远远多于附件中的数据,用人工算将花费大量精力。

如果你确认是三单合成的,问题现在倒能解决了,不知道你这个有没有2个单子加起来=5000的可能性?
4#
发表于 2014-1-16 20:20:49 | 显示全部楼层
用了个笨办法,把2单和3单的全部列举出来:
select * from
(SELECT a.name, a.amount+b.amount+c.amount as jg FROM 表2 AS a, 表2 AS b, 表2 AS c
where a.name & a.amount<>b.name & b.amount and a.name & a.amount<>c.name & c.amount and b.name & b.amount<>c.name & c.amount
and a.name=b.name and a.name=c.name and b.name=c.name
union
SELECT a.name, a.amount+b.amount as jg FROM 表2 AS a, 表2 AS b
where a.name & a.amount<>b.name & b.amount and a.name=b.name) as z
where z.jg=5000

点评

用ID,把ID相同的过滤掉  发表于 2014-1-17 10:09
5#
发表于 2014-1-16 20:22:51 | 显示全部楼层
玉树TMD临风 发表于 2014-1-16 20:20
用了个笨办法,把2单和3单的全部列举出来:
select * from
(SELECT a.name, a.amount+b.amount+c.amount a ...

不知道你同一个人有没有相同的amount,我是把同一个人相同的价格单给去掉了
6#
发表于 2014-1-16 21:06:12 | 显示全部楼层
lynnwang 发表于 2014-1-16 20:46
然后利用HAVING对结果进行条件筛选
SELECT Sum(Costmer.AMOUNT) AS 小计, Costmer.strName
FROM Costmer
...

你这个是把某人所有的价格全部加上后的值,楼主要的不一定是一个人的所有订单,有可能是2笔,有可能是3笔
7#
发表于 2014-1-17 17:40:57 来自手机 | 显示全部楼层
我做了一个查询,能列出所有两单或三单的组合,包括ID号,有个小问题,就是有些组合是重复的,暂时不知道怎么去掉,比如ID12,18,29合计5000远,29,12,18也是5000,结果都显示出来了来自: Android客户端

点评

SQL语句on ID3>ID2,ID2>ID1,这样可以去掉重复项  发表于 2014-1-21 10:43
8#
发表于 2014-1-17 19:33:57 | 显示全部楼层
这是查询语句代码,有些重复的不知道怎么去掉,你试试看
select * from (SELECT a.ID & "+" & b.ID & "+" & c.ID as id,a.strname,a.amount+b.amount+c.amount as amount
FROM Costmer a,costmer b,costmer c
where (a.id<>b.id and a.id<>c.id and b.id<>c.id) and (a.strname=b.strname and a.strname=c.strname and b.strname=c.strname)) z
where amount=5000


我只选取了3个单子,如果有2个单子你可以用union按这个思路再加一行代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-14 10:53 , Processed in 0.102437 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表