sql count, sort and group
Posted October 26, 2011on:
My sql knowledge has stayed roughly the same over the years — mostly select’s🙂 I have resolved to know more about SQL, like at least can work out those interview questions that ask you to find duplicates from a db table🙂
Here is one example (easy) I have worked out today.
mysql> select column_name, count(*) as c from table_name group by column_name order by c DESC;
This can group all the possible values of a column and count how many rows with each of those values and show the counts in descending order.