Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to select other column before aggregate of a subquery

select Name,TotalTrans as asd from (select Name, COUNT(name) as
TotalTrans from trans group by Name) as sub1 group by Name, TotalTrans
having TotalTrans = MAX(TotalTrans)

i want to get the name and the max value of the total transaction(count) that has been occured on the table

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would use a TOP query here:

SELECT TOP 1 name, COUNT(name) AS TotalTrans
FROM trans
GROUP BY name
ORDER BY COUNT(name) DESC;

If there could be more than one name tied for the highest count, then use TOP 1 WITH TIES or add another sorting level to ORDER BY which breaks the tie.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading