+ 4

MIN function in SQL

I am stuck on the MIN challenge in SQL - titled goal. It seems my issue is that I am having trouble selecting more data from the table beyond just the MIN value. I can get this code to work; SELECT MIN(salary) FROM employees; However when I want to select more data such as name or id, I can’t seem to get the code to work. Where do other values go in the code when the MIN value is used? I am having this issue specifically with the “GOAL” challenge.

28th Jan 2021, 2:03 AM
Karsa9Fingers
Karsa9Fingers - avatar
11 Respostas
+ 5
1. You should select team, scored goals and conceded goals from the league table according to the result. ========================== SELECT team, scored_goals, conceded_goals FROM league ========================== 2. You should use subqueries because aggregate function are not allowed in WHERE. ========================== SELECT MIN(conceded_goals) FROM league ========================== 3. Order by scored goals in descending order. ========================== ORDER BY scored_goals DESC; ========================== 4. So, the answer is : ========================== SELECT team, scored_goals, conceded_goals FROM league WHERE conceded_goals = (SELECT MIN(conceded_goals) FROM league) ORDER BY scored_goals DESC; ========================
10th May 2021, 5:56 AM
Signal Fish
Signal Fish - avatar
+ 5
SELECT firstname FROM staff WHERE salary BETWEEN 1500 AND 1900;
26th Apr 2022, 1:40 PM
Amare Gatie kibret
Amare Gatie  kibret - avatar
+ 1
You can achieve It by using sub query Like Select Id, Name,(Select Min(Salary) From Employee) as Salary From Employee Where Select Id, Name From Employee Provide you result by selecting Id and Name columns from Employee Table And (Select Min(Salary) From Employee) as Salary provide information about minimum Salary by selecting Salary from Employee Table With the combination of above two query you can get result as you expect
28th Jan 2021, 4:13 AM
Shashank Mishra
Shashank Mishra - avatar
+ 1
Thanks Callum Rushworth I just completed it! Weird it doesn't let me reply to your messages says keep doing the courses lol! Thanks man!
31st Mar 2021, 6:59 AM
Sirisha Tammina
Sirisha Tammina - avatar
0
Shashank Mishra That assisted me however now the output is changing all lf the “conceded goals” to be 2? here is my new code: SELECT team, scored_goals, (SELECT MIN(conceded_goals)FROM league) AS conceded_goals FROM league ORDER BY scored_goals DESC; The goal is to only display the two teams with the lowest conceded goals and put them in descending order by scored goals
28th Jan 2021, 12:35 PM
Karsa9Fingers
Karsa9Fingers - avatar
0
Apl wont let me respond to this with a solution
29th Mar 2021, 7:31 PM
Callum Rushworth
Callum Rushworth - avatar
0
it is showing up all the columns with average as 2 dont know why ugh!
31st Mar 2021, 6:14 AM
Sirisha Tammina
Sirisha Tammina - avatar
0
No problem👍
31st Mar 2021, 7:00 AM
Callum Rushworth
Callum Rushworth - avatar
0
Signal Fish Perfect Answer... Wohohooh
20th Jul 2021, 9:49 AM
Dark_Mix
Dark_Mix - avatar
0
SELECT firstname FROM staff WHERE salary BETWEEN 1500 AND 1900 ;
18th Nov 2023, 12:07 AM
Borico Okomo Nguema
Borico Okomo Nguema - avatar
- 2
SELECT team, scored_goals, (SELECT MIN(conceded_goals)FROM league) AS conceded_goals FROM league ORDER BY scored_goals DESC;
8th Mar 2021, 12:38 PM
Gulmira Abzhanova
Gulmira Abzhanova - avatar