Collections:
Using Group Functions in the ORDER BY Clause in MySQL
Can Group Functions Be Used in the ORDER BY Clause in MySQL?
✍: FYIcenter.com
If the query output is aggregated as groups, you can sort the groups by using group functions in the ORDER BY clause. The following statement returns how many links were created in each year in each tag. The group output is sorted by the count in each group in descending order:
mysql> SELECT tag, YEAR(created), COUNT(*) FROM fyi_links GROUP BY tag, YEAR(created) ORDER BY COUNT(*) DESC; +------+---------------+----------+ | tag | YEAR(created) | COUNT(*) | +------+---------------+----------+ | DBA | 2006 | 2 | | DEV | 2006 | 1 | | SQA | 2006 | 1 | | DBA | 2005 | 1 | | DEV | 2004 | 1 | | SQA | 2003 | 1 | +------+---------------+----------+ 6 rows in set (0.00 sec)
⇒ SELECT Statements with JOIN and Subqueries in MySQL
⇐ Using Multiple Columns in GROUP BY in MySQL
2017-12-31, 2470🔥, 0💬
Popular Posts:
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
How To Convert Binary Strings into Hexadecimal Character Strings in SQL Server? When a query returns...
What are single-byte character string data types supported in SQL Server Transact-SQL? Single-byte c...
What To Do If the StartDB.bat Failed to Start the XE Instance in Oracle? If StartDB.bat failed to st...
How To Drop an Index in Oracle? If you don't need an existing index any more, you should delete it w...