Clickhouse - Cumulative Sum or Running Total and Percent to Total

Viewed 9914

We have been very encouraged by Clickhouse. However, as we are trying to port all of our existing scripts to Clickhouse, we are running into few roadblocks. For example: CUMULATIVE SUM or RUNNING TOTAL. We are trying to find an equivalent of Window Functions e.g. SUM(SALES) OVER (PARTITION BY PRODUCT ORDER BY SALES)

  • Is there a way to get Cumulative Sum or Running Total. Any inputs or guidance is much appreciated. Thanks!


  • This is my second question on Clickhouse (again a fantastic database). We have to port our script which calculates "Percent to total".

    For e.g

    Product | Sales
    
    P1  100 
    
    P2  200
    
    P3  150
    
    P4  50
    

    We are looking at writing a script which can populate

    Product, Sales, PercenttoTotal
    
    P1, 100, 20%
    
    P2, 200, 40%
    
    P3, 150, 30%
    
    P4, 50,  10%
    

    Is there a quick way via various functions in Clickhouse using which we can accomplish this. Thanks in advance.

  • 1 Answers
    Related