尝试根据 SQL 中的分组获得结果
我可能把这个问题过于复杂化了,但本质上我有一个表,其中包含:
- 收据编号
- 帐单值
- 反映帐单类型的整数(1、2 或 3)。
每件已售商品都有一行,并且每张账单上可以有多个商品,因此收据编号可以有多个实例(例如,如果我在同一张账单上出售两件商品,则收据编号中将有两个条目)收据编号为 123 的表格)
我要查找的是包含多个类型账单的账单计数(以及可能的价值)。
这实际上是在VFP中...
I'm possibily overcomplicating this, but essentially I have a table that contains:
- a receipt number
- a bill value
- an integer that reflects the type of bill (1, 2 or 3).
There's a line for each item that's sold, and there can be more than one item on each bill, so there can be multiple instances of the receipt number (e.g. if I sell two items on the same bill, there will be two entries in the table with receipt number 123)
What I'm looking for is a count (and potentially the value) of bills where they contain more than one type of bill.
This is actually in VFP...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,如果您有:
ID, value, type
1, 10.00, 8
1, 20.00, 8
2, 15.00, 5
2, 16.00, 7
3, 30.00, 8
您希望看到计数为 1 且总和为 31.00?
这似乎在 SQL 中有效,所以我猜想 vfp 中有类似的东西(我记不起来了!)
基本上第二列会给你总和,行数将是计数。
So if you have:
ID, value, type
1, 10.00, 8
1, 20.00, 8
2, 15.00, 5
2, 16.00, 7
3, 30.00, 8
You would want to see a count of 1 and a sum of 31.00?
This seems to work in SQL, so I guess that there is something equivalent in vfp (no way can I remember!)
Basically the second column will give you the sum and the number of rows will be the count.
在没有您的表结构的情况下,我即兴发挥...
您在查询中只能有一个计数(不同的...),所以我已经针对您的账单类型列完成了它。然后应用 HAVING 子句来获取具有多种类型的数据。
Without having your table structure, I improvised...
You can only have ONE COUNT( DISTINCT ... ) in a Query, so I've done it against your Bill Type column. Then applying the HAVING clause to get those that had more than one type.