sql - Select distinct combinations of values -
i have table x values , y values, both int. want group on x value condition contains distinct combination of y values. want see total number of each combination.
i tried using sum ( power (2, y)), generates numbers big y can 300 in cases.
+--------------+--------------+ | x | y | +--------------+--------------+ | 1 | 1 | | 1 | 2 | | 1 | 4 | | 1 | 6 | | 2 | 1 | | 2 | 2 | | 2 | 4 | | 2 | 6 | | 3 | 2 | | 3 | 3 | | 3 | 5 | | 4 | 2 | | 4 | 3 | | 4 | 5 | | 5 | 2 | | 5 | 3 | | 5 | 6 | +--------------+--------------+
i want result like:
+--------------+--------------+ | x | count | +--------------+--------------+ | 1 | 2 | | 3 | 2 | | 5 | 1 | +--------------+--------------+
based on description (but not on sample data) next query should do:
select x, count(distinct y) tbl group x
Comments
Post a Comment