Write and run SAS programs in your web browser

How to sum and then find max in sql

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to sum and then find max in sql

I need to sum the hits of each player and then show the max one. This is my code, but I has syntax problem on this nested sql, can someone help to figure out?

proc sql;
title2"Part 2d";
select distinct PlayerID, min(YearID) label="First Year", sum(H) as Total_Hits
   group by PlayerID
   where Total_Hits=max(Total_Hits);
quit;
title;

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 9,662

Re: How to sum and then find max in sql

[ Edited ]

 

proc sql;
select *
 from (
select sex,sum(height) as total
 from sashelp.class
  group by sex
)
   having  total=max( total);
quit;

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: How to sum and then find max in sql

What nested SQL?

I can see off the bat that where should be having.

Solution
2 weeks ago
Super User
Posts: 9,662

Re: How to sum and then find max in sql

[ Edited ]

 

proc sql;
select *
 from (
select sex,sum(height) as total
 from sashelp.class
  group by sex
)
   having  total=max( total);
quit;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 147 views
  • 0 likes
  • 3 in conversation