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, 2515🔥, 0💬
Popular Posts:
How To Connect to a MySQL Server with a Port Number in MySQL? If you want to connect a MySQL server ...
How To Look at the Current SQL*Plus System Settings in Oracle? If you want to see the current values...
What Is Transport Network Substrate (TNS) in Oracle? TNS, Transport Network Substrate, is a foundati...
How To Convert Numeric Values to Character Strings in MySQL? You can convert numeric values to chara...
Can You Drop an Index Associated with a Unique or Primary Key Constraint in Oracle? You can not dele...