Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Training SQL exercice

Author  Topic 

tofoo
Starting Member

3 Posts

Posted - 2015-04-10 : 08:45:11
Hello,

I am new on the forum, i do a sql exercise and a wish to have advice.
Here is the BDD (sorry for the quality)
http://imagesia.com/test-sql_wjel

Question 1 : Write SQL to show details of manager who manages more than 3 employees

My answer :
select * from employees em, job_history jh, departments dep
where jh.employees_ID=em.employees_ID
and jh.end_data is null
and dep.manager_ID=em.manager_ID
having (em.employees_ID)>3;

Question 2 : Write SQL to show country name, city and number of departments where department has more than 5 employees

My answer :
select co.country_name, lo.city, lo.postal_code
from countries co, locations lo, employees em, departments dep
where co.countries_ID=lo.countries_ID
and lo.location_ID=dep.location_ID
and dep.manager_ID=em.manager_ID
having (em.employees_ID)5;

Question 3 : Write SQL to show the details of employees drawing the highest salary in the department

My answer :
select em.*, jo.jobs_titles
from employees em, jobs jo
where em.job_ID=k=jo.em.job_ID
and max(max_salary);

Question 4 : Write SQL to show employee name, job title, start date and end date of past jobs of all employees with commission percentage null

My answer :
select em.first_name,em.last_name, jo.jobs_titles, jh.start_date, jh.end_date
from employees em, jobs jo, job_history jh
where em.commission_pct is null;

Thanks !

tofoo
Starting Member

3 Posts

Posted - 2015-04-11 : 12:40:56
Anyone please ?
Go to Top of Page

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2015-04-11 : 17:03:34
First of all, try executing your queries. That way you'll see if it works, and even if it doesn't, the error message will point you in the direction of, what might be wrong.
Secondly, you will probably want to look into the terms "group by" and subqueries.
Lastly, do you self a favour and read up on the different ways of joining tables.
Go to Top of Page

tofoo
Starting Member

3 Posts

Posted - 2015-04-12 : 07:48:56
Hello bitsmed,

It's a paper exercise so i can't execute the query.
I want external opinion to see if i am in the good direction.
Go to Top of Page
   

- Advertisement -