Created
April 10, 2019 18:30
-
-
Save den-crane/8f2db1e24564522788a2e1010dd38dea to your computer and use it in GitHub Desktop.
CH percentage from total using groupArray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT grp, ga.1 key, ga.2 value, vsum, value / vsum*100 percent | |
FROM (SELECT grp, groupArray(tuple (key,value)) ga, SUM(value) vsum | |
FROM (SELECT 1 grp,'k1' key,33 value UNION ALL SELECT 1, 'k2', 11 UNION ALL SELECT 2,'k1', 0 UNION ALL SELECT 2,'k2',1) | |
GROUP BY grp) Array JOIN ga | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment