Collections:
Using Group Functions in the ORDER BY Clause in SQL Server
Can Group Functions Be Used in the ORDER BY Clause in SQL Server?
✍: 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 the maximum "counts" in each group, determined by a unique combination of tag and year. The group output is sorted by the maximum "counts" in each group in ascending order:
SELECT tag, YEAR(created), MAX(counts) FROM fyi_links GROUP BY tag, YEAR(created) ORDER BY MAX(counts) GO tag year(created) max(counts) DEV 2006 120 DBA 2006 390 DEV 2004 439 SQA 2007 728 SQA 2003 828 DBA 2005 960 DBA 2007 972
⇒ Creating and Managing Triggers in SQL Server
⇐ Using Multiple Columns in the GROUP BY Clause in SQL Server
⇑ Using SELECT Statements and GROUP BY Clauses in SQL Server
2016-10-25, 2527🔥, 0💬
Popular Posts:
What Are the Underflow and Overflow Behaviors on FLOAT Literals in SQL Server Transact-SQL? If you e...
How To Connect to a MySQL Server with a Port Number in MySQL? If you want to connect a MySQL server ...
How To Download Oracle Database 10g XE in Oracle? If you want to download a copy of Oracle Database ...
What Happens to the Current Transaction If a START TRANSACTION Is Executed in MySQL? If you are in a...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...