Author |
Topic |
shyy
Starting Member
3 Posts |
Posted - 2013-10-21 : 23:33:44
|
Hi everyone,I am having trouble reformatting this older syntax to the newer syntax.For questions 6 and 7, how would I reformat this to match this type of format?SELECT Employee_NameFROM EMPLOYEE_T e,EMPLOYEE_SKILLS_T s,SKILL_T tWHERE e.Employee_ID = s.Employee_IdAND s.Skill_Id = t.Skill_IdAND t.Skill_Description = '12in Band Saw'AND e.Employee_ID <> s.Employee_IdAND s.Skill_Id = t.Skill_IdAND t.Skill_Description <> '12in Band Saw'Thank Youhttp://imageshack.us/photo/my-images/853/mz34.jpg/ |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-10-22 : 00:19:25
|
The link which you shared is not opened for me...Any way, try this? ( rectified some of typos in the above query)SELECT Employee_Name FROM EMPLOYEE_T e, EMPLOYEE_SKILLS_T s, SKILL_T tWHERE e.Employee_ID = s.Employee_Id AND s.Skill_Id = t.Skill_Id AND t.Skill_Description = '12in Band Saw' AND e.Employee_ID <> s.Employee_IdAND s.Skill_Id = t.Skill_IdAND t.Skill_Description <> '12in Band Saw'The highlighted part is fully opposite to other conditions available in the above query...--Chandu |
|
|
shyy
Starting Member
3 Posts |
Posted - 2013-10-22 : 00:53:30
|
Thanks for the reply,The highlighted part is another condition since I need to say which Employee only has one skills where as the one you selected shows employees that have multiple skills.Please check out this url http://imageshack.us/f/853/mz34.jpg/This is the correct code, I just prefer this to look like the format above.SELECT Employee_NameFROM EMPLOYEE_TWHERE Employee_ID IN (SELECT Employee_Id FROM EMPLOYEE_SKILLS_T WHERE Skill_Id IN (SELECT Skill_Id FROM SKILL_T WHERE Skill_Description = '12in Band Saw')) AND Employee_ID NOT IN (SELECT Employee_Id FROM EMPLOYEE_SKILLS_T WHERE Skill_Id IN (SELECT Skill_Id FROM SKILL_T WHERE Skill_Description <> '12in Band Saw')) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-10-22 : 02:38:02
|
-- AlternateSELECT Employee_Name, Employee_idFROM EMPLOYEE_TWHERE Employee_id IN (SELECT est.Employee_IdFROM EMPLOYEE_SKILLS_T est JOIN SKILL_T st ON est.Skill_Id = st.Skill_IdGROUP BY est.Employee_IdHAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 ) If the above is NOT, post us back the result of the below querySELECT est.Employee_IdFROM EMPLOYEE_SKILLS_T est JOIN SKILL_T st ON est.Skill_Id = st.Skill_IdGROUP BY est.Employee_IdHAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-22 : 08:08:20
|
[code]SELECT e.Employee_Name, e.Employee_idFROM EMPLOYEE_T eINNER JOIN (SELECT est.Employee_IdFROM EMPLOYEE_SKILLS_T est JOIN SKILL_T st ON est.Skill_Id = st.Skill_IdGROUP BY est.Employee_IdHAVING MIN(st.Skill_Description) = MAX(st.Skill_Description)AND MIN(st.Skill_Description)='12in Band Saw')e1ON e1.Employee_Id = e.Employee_Id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
shyy
Starting Member
3 Posts |
Posted - 2013-10-22 : 10:09:06
|
Thank You guys both worked!Bandi:What does this do?HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 ) visakh16:Why did you use HAVING MIN = MAX and then use MIN and e1 at the end??The professor gave us an SQL assignment but never showed us how to actually use it..Thanks again for the help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-22 : 10:10:50
|
you're welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-22 : 14:34:40
|
quote: Originally posted by shyy Thank You guys both worked!Bandi:What does this do?HAVING SUM( CASE WHEN st.Skill_Description = '12in Band Saw' then 0 else 1 end ) = 0 ) visakh16:Why did you use HAVING MIN = MAX and then use MIN and e1 at the end??The professor gave us an SQL assignment but never showed us how to actually use it..Thanks again for the help.
MIN = MAX was to ensure you've only one unique Skill_Description available for that employee. Second condition will ensure value is '12in Band Saw' which is what you wantede1 is alias ie name given to derived table which contains the query ie query behaving like another table.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|