kkfnui
V2EX  ›  问与答

influxdb 如何按 field 去重计数

  •  
  •   kkfnui · Dec 19, 2017 · 3432 views
    This topic created in 3080 days ago, the information mentioned may be changed or developed.
    SELECT count("user_id") FROM "alg_read_log" Where time >= now() - 7d GROUP BY time(1d) fill(null)
    
    SELECT count("id") FROM "alg_read_log" Where time >= now() - 7d GROUP BY time(1d) fill(null)
    

    以上两个语句返回的数据一样。期望第一个语句能够对用户总数计数,而非记录数。在 influxdb 中是否有方法可以实现呢?

    1 replies    2017-12-19 11:15:32 +08:00
    yongzhong
        1
    yongzhong  
       Dec 19, 2017   ❤️ 1
    获得总数要 JOIN 才行
    为何不加个定时脚本每分钟把 count 再存到另外一个 measurement 里然后读这个就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4136 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 00:06 · PVG 08:06 · LAX 17:06 · JFK 20:06
    ♥ Do have faith in what you're doing.