sql - How to do select count(*) group by and select * at same time? -
for example, have table:
id | value 1 hi 1 yo 2 foo 2 bar 2 hehe 3 ha 6 gaga
i want query id, value; meanwhile returned set should in order of frequency count of each id.
i tried query below don't know how id , value column @ same time:
select count(*) table group id order count(*) desc;
the count number doesn't matter me, need data in such order.
desire result:
id | value 2 foo 2 bar 2 hehe 1 hi 1 yo 3 ha 6 gaga can see because id:2 appears times(3 times), it's first on list, id:1(2 times) etc.
select t.id, t.value table t inner join ( select id, count(*) cnt table group id ) x on x.id = t.id order x.cnt desc
Comments
Post a Comment