@@ -3595,6 +3595,103 @@ SELECT ABS(percentile_cont(0.5) WITHIN GROUP (ORDER BY c3) - approx_percentile_c
35953595----
35963596true
35973597
3598+ # Test percentile_cont without WITHIN GROUP clause (alternate syntax)
3599+ query R
3600+ SELECT percentile_cont(c2, 0.5) FROM aggregate_test_100
3601+ ----
3602+ 3
3603+
3604+ query R
3605+ SELECT percentile_cont(c2, 0.0) FROM aggregate_test_100
3606+ ----
3607+ 1
3608+
3609+ query R
3610+ SELECT percentile_cont(c2, 1.0) FROM aggregate_test_100
3611+ ----
3612+ 5
3613+
3614+ query R
3615+ SELECT percentile_cont(c2, 0.25) FROM aggregate_test_100
3616+ ----
3617+ 2
3618+
3619+ query R
3620+ SELECT percentile_cont(c2, 0.75) FROM aggregate_test_100
3621+ ----
3622+ 4
3623+
3624+ # Verify alternate syntax gives same results as WITHIN GROUP syntax
3625+ query B
3626+ SELECT percentile_cont(c2, 0.5) = percentile_cont(0.5) WITHIN GROUP (ORDER BY c2) FROM aggregate_test_100
3627+ ----
3628+ true
3629+
3630+ query B
3631+ SELECT percentile_cont(c3, 0.5) = percentile_cont(0.5) WITHIN GROUP (ORDER BY c3) FROM aggregate_test_100
3632+ ----
3633+ true
3634+
3635+ # Test alternate syntax with GROUP BY
3636+ query TR
3637+ SELECT c1, percentile_cont(c3, 0.5) FROM aggregate_test_100 GROUP BY c1 ORDER BY c1
3638+ ----
3639+ a -25
3640+ b 17
3641+ c 1
3642+ d 46.5
3643+ e 64
3644+
3645+ # Verify alternate syntax with GROUP BY gives same results as WITHIN GROUP
3646+ query TB
3647+ SELECT c1, percentile_cont(c3, 0.95) = percentile_cont(0.95) WITHIN GROUP (ORDER BY c3) FROM aggregate_test_100 GROUP BY c1 ORDER BY c1
3648+ ----
3649+ a true
3650+ b true
3651+ c true
3652+ d true
3653+ e true
3654+
3655+ # Test ascending vs descending equivalence: percentile_cont(0.4) ASC should equal percentile_cont(0.6) DESC
3656+ # This tests the mathematical property that the pth percentile ascending = (1-p)th percentile descending
3657+ # Using a simple controlled dataset to demonstrate the property
3658+
3659+ # Show 0.4 ascending
3660+ query R
3661+ SELECT percentile_cont(0.4) WITHIN GROUP (ORDER BY v) FROM (VALUES (1), (2), (3), (4), (5)) as t (v)
3662+ ----
3663+ 2.6
3664+
3665+ # Show 0.6 descending (should be same as 0.4 ascending)
3666+ query R
3667+ SELECT percentile_cont(0.6) WITHIN GROUP (ORDER BY v DESC) FROM (VALUES (1), (2), (3), (4), (5)) as t (v)
3668+ ----
3669+ 2.6
3670+
3671+ # Show 0.3 ascending
3672+ query R
3673+ SELECT percentile_cont(0.3) WITHIN GROUP (ORDER BY v) FROM (VALUES (10), (20), (30), (40), (50)) as t (v)
3674+ ----
3675+ 21.99999
3676+
3677+ # Show 0.7 descending (should be same as 0.3 ascending)
3678+ query R
3679+ SELECT percentile_cont(0.7) WITHIN GROUP (ORDER BY v DESC) FROM (VALUES (10), (20), (30), (40), (50)) as t (v)
3680+ ----
3681+ 22
3682+
3683+ # Show 0.25 ascending on larger dataset
3684+ query R
3685+ SELECT percentile_cont(0.25) WITHIN GROUP (ORDER BY v) FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8)) as t (v)
3686+ ----
3687+ 2.75
3688+
3689+ # Show 0.75 descending (should be same as 0.25 ascending)
3690+ query R
3691+ SELECT percentile_cont(0.75) WITHIN GROUP (ORDER BY v DESC) FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8)) as t (v)
3692+ ----
3693+ 2.75
3694+
35983695# array_agg_zero
35993696query ?
36003697SELECT ARRAY_AGG([])
0 commit comments