christian-schlichtherle commented on issue #17994:
URL: https://github.com/apache/druid/issues/17994#issuecomment-2867588855

   It can be fixed with a little refactoring:
   
   ```
   WITH t1 AS (
     SELECT *
     FROM (
       VALUES
       ('18-19', 'female', 84),
       ('18-19', 'male', 217),
       ('20-29', 'female', 321),
       ('20-29', 'male', 820),
       ('30-39', 'female', 63),
       ('30-39', 'male', 449),
       ('40-49', 'female', 10),
       ('40-49', 'male', 83),
       ('50-59', 'female', 2),
       ('50-59', 'male', 13)
     ) AS data(Age, Gender, Visitors)
   ),
   t2 AS (
     SELECT Age, Gender, CAST(SUM(Visitors) AS double) / (SELECT SUM(Visitors) 
FROM t1) AS Share
     FROM t1
     GROUP BY 1, 2
   )
   SELECT *
   FROM t2
   PIVOT (MAX(Share) FOR Gender IN ('female' AS Women, 'male' AS Men))
   ORDER BY 1
   ```
   
   So it seems like the CROSS JOIN in t3 is breaking the PIVOT.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to