SQL Challenges-1: Average experience for each scheme
From the following tables write a SQL query to display those managers who have average experience for each scheme.
Input:
Table: managing_body
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
manager_id | int(11) | NO | PRI | ||
manager_name | varchar(255) | YES | |||
running_years | int(11) | YES |
Data:
manager_id | manager_name | running_years |
---|---|---|
51 | James | 5 |
52 | Cork | 3 |
53 | Paul | 4 |
54 | Adam | 3 |
55 | Hense | 4 |
56 | Peter | 2 |
Table: scheme
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
scheme_code | int(11) | NO | PRI | ||
scheme_manager_id | int(11) | NO | PRI |
Data:
scheme_code | scheme_manager_id |
---|---|
1001 | 51 |
1001 | 53 |
1001 | 54 |
1001 | 56 |
1002 | 51 |
1002 | 55 |
1003 | 51 |
1004 | 52 |
Sample Solution-1:
SQL Code(MySQL):
Sample Output:
scheme_code|Average year of experience| -----------|--------------------------| 1001| 3.50| 1002| 4.50| 1003| 5.00| 1004| 3.00|
OR
Sample Solution-2:
SQL Code(MySQL):
SQL Code Editor:
Contribute your code and comments through Disqus.
Previous: Students achieved 100 percent for the first year of each examination of every subject.
Next: Schemes executed by minimum number of employees.