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, 1417🔥, 0💬
Popular Posts:
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
How To Get the Definition of a Stored Procedure Back in SQL Server Transact-SQL? If you want get the...
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL? Random numbers a...
Where to find MySQL database server tutorials? Here is a collection of tutorials, tips and FAQs for ...