Giter VIP home page Giter VIP logo

Comments (1)

UnamedRus avatar UnamedRus commented on September 23, 2024

Probably blocked by the same limitation like here #55058 (comment)

Check those approaches as well https://kb.altinity.com/altinity-kb-queries-and-syntax/top-n-and-remain/

Your particular query also can be done using "scalar" instead of cte.

WITH (
        SELECT (id, kind, count() AS c)
        FROM events
        GROUP BY
            id,
            kind
        ORDER BY c DESC
        LIMIT 1
    ) AS s
SELECT
    id,
    kind,
    count() AS c,
    toStartOfInterval(time, toIntervalSecond(20)) AS timestamp,
    s.3
FROM events AS t
WHERE (t.id = (s.1)) AND ((s.2) = t.kind)
GROUP BY
    timestamp,
    id,
    kind

Query id: 2161d7c6-24da-4890-b422-44902fb00a69

┌─id─────┬─kind───┬───c─┬───────────timestamp─┬─tupleElement(s, 3)─┐
│ item 9 │ kind 94422024-05-22 02:16:406249 │
│ item 9 │ kind 94482024-05-22 02:14:206249 │
│ item 9 │ kind 94032024-05-22 02:15:006249 │
│ item 9 │ kind 93932024-05-22 02:15:206249 │
│ item 9 │ kind 94092024-05-22 02:14:006249 │
│ item 9 │ kind 91332024-05-22 02:12:206249 │
│ item 9 │ kind 94152024-05-22 02:12:406249 │
│ item 9 │ kind 94272024-05-22 02:16:006249 │
│ item 9 │ kind 92942024-05-22 02:17:206249 │
│ item 9 │ kind 94112024-05-22 02:13:406249 │
│ item 9 │ kind 94102024-05-22 02:15:406249 │
│ item 9 │ kind 94132024-05-22 02:14:406249 │
│ item 9 │ kind 94112024-05-22 02:17:006249 │
│ item 9 │ kind 93992024-05-22 02:13:006249 │
│ item 9 │ kind 93962024-05-22 02:16:206249 │
│ item 9 │ kind 94452024-05-22 02:13:206249 │
└────────┴────────┴─────┴─────────────────────┴────────────────────┘

from clickhouse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.