Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to use Group by and Order by together in Sql?
Posted
Updated 18-Feb-18 23:44pm

Like this:
SQL
SELECT Username, COUNT(Posts)
FROM MyTable
GROUP BY Username
ORDER BY COUNT(Posts)
 
Share this answer
 
Hi..
SQL
SELECT value1, value2, COUNT(value1) AS val
FROM table_name GROUP by value1 , value2
HAVING val > 0 ORDER BY value2 DESC

Only Groupby
SQL
SELECT year, SUM(profit) FROM sales GROUP BY year;


Thank u
 
Share this answer
 
SQL
group by id
 
order by name desc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900