Skip to content
Advertisement

What is the smallest and largest individual for Charge Hour for Job Class?

I need to answer this tricky question in SQL, I tried many ways and finally got this query which retrieves only MAX SUM or MIN SUM without the respective employee.

This code retrieves only the MAX charge SUM values but I need it with MAX SUM value (group by job code) with the employee ID or Name as request in the question.

here is the table create and insert statement.

I highly appreciate your help to solve the above question. Thank you.

Advertisement

Answer

You want help, so you also have to make the effort to present a mre see Why should I provide a Minimal Reproducible Example for a very simple SQL query?

This what you want gives a very ugly query

JOB_CODE2019 | maxcharge | empnamemax         | mincharge | empnamemin        
-----------: | --------: | :----------------- | --------: | :-----------------
         503 |    633.75 | June Arbough       |    633.75 | June Arbough      
         510 |     62.42 | James Frommer      |     62.42 | James Frommer     
         501 |    406.35 | Ralph Washington   |    251.55 | Anne Ramoras      
         502 |    829.50 | Alice Johnson      |    178.50 | John News         
         508 |    529.10 | Annelise Jones     |    120.25 | elbert Joenbrood  
         506 |    107.48 | Geoff Wabash       |    107.48 | Geoff Wabash      
         507 |     55.14 | arlene Smithson    |     55.14 | arlene Smithson   
         500 |     85.80 | William Smithfield |     85.80 | William Smithfield

db<>fiddle here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement