尝试根据 SQL 中的分组获得结果

发布于 2024-11-26 07:47:20 字数 278 浏览 0 评论 0原文

我可能把这个问题过于复杂化了,但本质上我有一个表,其中包含:

  • 收据编号
  • 帐单值
  • 反映帐单类型的整数(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-12-03 07:47:20

因此,如果您有:

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 中有类似的东西(我记不起来了!)

SELECT BillId, SUM(Value)  FROM 
    (SELECT BillId, SUM(Value) AS Value, COunt(Type) AS TypeCount  
    FROM Bills GROUP BY BillId, Type) AS InnerGroup
GROUP BY BillId, TypeCount
HAVING Count(TypeCount) > 1

基本上第二列会给你总和,行数将是计数。

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!)

SELECT BillId, SUM(Value)  FROM 
    (SELECT BillId, SUM(Value) AS Value, COunt(Type) AS TypeCount  
    FROM Bills GROUP BY BillId, Type) AS InnerGroup
GROUP BY BillId, TypeCount
HAVING Count(TypeCount) > 1

Basically the second column will give you the sum and the number of rows will be the count.

你不是我要的菜∠ 2024-12-03 07:47:20

在没有您的表结构的情况下,我即兴发挥...

SELECT ;
      rcptNum, ;
      COUNT( distinct BillType ) DistTypes, ;
      SUM( billValue ) TotalBill;
   FROM ;
      Bills ;
   GROUP BY ;
      rcptNum ;
   HAVING ;
      DistTypes > 1;
   INTO ;
      CURSOR C_YourResults READWRITE

您在查询中只能有一个计数(不同的...),所以我已经针对您的账单类型列完成了它。然后应用 HAVING 子句来获取具有多种类型的数据。

Without having your table structure, I improvised...

SELECT ;
      rcptNum, ;
      COUNT( distinct BillType ) DistTypes, ;
      SUM( billValue ) TotalBill;
   FROM ;
      Bills ;
   GROUP BY ;
      rcptNum ;
   HAVING ;
      DistTypes > 1;
   INTO ;
      CURSOR C_YourResults READWRITE

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文