【问题标题】:QUERY results with count, group, order functions带有计数、分组、排序功能的查询结果
【发布时间】:2019-06-26 01:02:42
【问题描述】:

我想从查询中返回 5 列数据,加上第一列的计数。

我想要的其他几件事是仅包含活动的列表(由 M 列中的标记“包含”存储)并且我希望数据是随机的(我通过创建一个随机数生成器来做到这一点在 P 列)。最后两个都不应该显示。我想要返回的数据位于 Q、R、S、T、U 列中。

我的数据如下所示:

M       N       O       P       Q           R       S       T       U
Active  Text    Text    RN      Phone#      ID      Name    Level   Location
Include text    text    0.51423 10000001    1223    Bob     Level 2 Boston
Include text    text    0.34342 10000005    2234    Dylan   Level 3 San Francisco
Exclude text    text    0.56453 10000007    2311    Janet   Level 8 Des Moines
Include text    text    0.23122 10000008    2312    Gina    Level 8 Houston
Include text    text            10000001    1225    Ronda   Level 3 Boston
Include text    text            10000001    1236    Nathan  Level 2 Boston

因此,理想情况下,结果如下所示:

count Phone#    Phone#      ID      Name    Level       Location
3               10000001    1223    Bob     Level 2     Boston
1               10000005    2234    Dylan   Level 3     San Francisco
1               10000008    2312    Gina    Level 8     Houston

我不在乎电话号码后面显示的 ID 或姓名,只要它是列表中的号码之一即可。

现在,我已经能够让函数单独工作(ORDER 和 COUNT),但不能让两者在 1 个函数中工作:

工作:

=QUERY(Function!M:U, "SELECT count (Q), Q where O = 'Include' group by Q")

=QUERY(Function!M:U, "SELECT Q, R, S, T, U where O = 'Include' ORDER BY P DESC")

没用:

=QUERY(Function!M:U, "SELECT count (Q), Q group by Q, R, S, T, U where O = 'Include' group by Q ORDER BY P DESC, R, S, T, U")

=QUERY(Function!M:U, "SELECT count (Q), Q, R, S, T, U group by Q where O = 'Include' group by Q ORDER BY P DESC")

=QUERY(Function!M:U, "SELECT count (Q), Q group by Q where O = 'Include' group by Q ORDER BY P DESC, R, S, T, U")

也许有人知道我在结合两种不同类型的语法时哪里出错了?非常感谢您的帮助! :)

【问题讨论】:

  • 你能告诉我们更多显示重复记录的数据吗?看起来好像电话号码 10000001 重复了 3 次,但不清楚电话号码 10000001 是否总是与 1223 Bob 2 级波士顿一起使用,或者是否可以再次与 1224 查理 3 级纽约一起使用。
  • 我只想按电话号码分组,其他的都无关紧要。
  • 你试过SELECT COUNT(Q), Q, R, S, T, U WHERE O = 'Include' GROUP BY Q, R, S, T, U ORDER BY P DESC吗?
  • Joakim,您的公式返回以下错误:无法解析函数查询参数 2 的查询字符串:COL_IN_ORDER_MUST_BE_IN_SELECT:P

标签: google-sheets google-sheets-formula array-formulas google-sheets-query gs-vlookup


【解决方案1】:
=ARRAYFORMULA({"count Phone#", "Phone#", "ID", "Name", "Level", "Location"; 
 QUERY(Function!M3:U, 
 "select count(Q),Q where P is not null group by Q label count(Q)''", 0),
 IFERROR(VLOOKUP(INDEX(QUERY(Function!M3:U, 
 "select Q,count(Q) where P is not null group by Q label count(Q)''", 0),,1),
 QUERY(Function!M3:U, 
 "select Q,R,S,T,U where P is not null order by P desc", 0), {2, 3, 4, 5}, 0))})


单元格P2

=ARRAYFORMULA({"RN"; IF(M3:M="Include", RANDBETWEEN(ROW(A3:A),99^9), )})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2012-07-07
    • 2012-09-23
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多