【问题标题】:How can I do the equivalent of a COUNT/GROUP BY in Excel?如何在 Excel 中执行相当于 COUNT/GROUP BY 的操作?
【发布时间】:2013-03-01 01:17:34
【问题描述】:

我在 Excel 电子表格中有一个表格。我想得到相当于做类似的事情

SELECT col1, COUNT(col1), COUNT(col2)
FROM table
GROUP BY col1

在 SQL 中。我试图使用数据透视表,我可能想多了,但我不习惯在 Excel 中工作,无法弄清楚。

感谢所有帮助。谢谢。

【问题讨论】:

  • COUNT(col1) 不会总是 1 吗?这对你有用吗?
  • 我可能问错了这个问题或认为 SQL 也错了...假设一个值可以在第 1 列中出现多次。我对每个唯一值出现的次数感兴趣,并且我还对第 2 列中出现在它旁边的唯一值的数量感兴趣。

标签: excel count group-by pivot-table


【解决方案1】:

在单元格公式中它会是(即)

    //Cell Formula
    =Count(A1:A50) // Range
    =Count(A1, A3, A5) // Specific Cells


   // in VBA

   =Sheet1.Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count

  // Where "A" is the column and 'SpecialCells(xlCellTypeConstants)' returns non-blank cells

//如果需要检查vba中的特定值:

  Dim counter As Integer
 counter = 0

 For Each c In Sheet1.Range("A1:A100").Cells

      If c.Value = "Something" Then
        counter = counter + 1
      End If


 Next

 // Then get your value of the counter variable

您可能需要执行嵌套循环才能获得所需的内容。

【讨论】:

    【解决方案2】:

    在后台打开 Access 实例。放数据。通过 SQL 查询。

    【讨论】:

      猜你喜欢
      • 2010-10-24
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 2018-01-14
      • 2019-04-26
      • 2012-10-02
      • 1970-01-01
      相关资源
      最近更新 更多