Web Design Forums

Database Systems Help

Discussion and help on database systems such as MySQL, MSSql, SQLite, PostgreSQL

Looking for the SQL Legend!



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old May 21 '04, 05:43 AM (#1)
toadeny is offline
"I'm addicted to WDF"
 
toadeny's Avatar
 
Join Date: May 2003
Location: Wellington, New Zealand
Posts: 188
toadeny is on a distinguished road
Looking for the SQL Legend!

Hi there

I am looking for a way in MS Access SQL to bring up the top 5 employees who have never failed a test, and if they have failed, they will not be shown on this list.

and also

I wish to see all of the employees that have failed at least one test and also passed one test at the same time.

Does any one have any ideas on any way to sovle these problems?

I would be extremely grateful if anyone would be able to solve any one if not all of these problems

These are the tables and their Fields
HISTORY
TestID
TestedON
EmployeeId
TestType
Passed (boolean)
DateStarted

TEST
TestType
TestDesc
Critical
Unit

EMPLOYEE
EmployeeId
FirstName
Surname
Date Of Birth
DateStarted
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 21 '04, 12:21 PM (#2)
Wired is offline
WDF Alien Overlord
 
Wired's Avatar
 
Join Date: April 2003
Posts: 6,369
Wired is just really niceWired is just really niceWired is just really niceWired is just really nice
Send a message via AIM to Wired
Part of it depends on how you want to measure the top 5 employees. You may have 20 employees that have never failed. I'm assuming you want to list the top 5 with the largest amount of tests taken, or perhaps by DateStarted?

Code:
SELECT E.EmployeeId, E.FirstName, E.Surname, H.TestID
FROM HISTORY as H, EMPLOYEE as E
WHERE H.Passed = 1
AND H.EmployeeID = E.EmployeeID
ORDER BY E.EmployeeId, H.TestID ASC
This code should find all the tests that have been passed. I think what you want will require more than one query. The only way I can see doing it with only 1 query is to add a value to the Employee table (a boolean) that is TRUE if they have never taken a test or have taken at least one test and passed them all. Ergo, FALSE if they have taken at lease one test and failed at least one. This way, whenever an employee takes a new test and the grade is recorded, the boolean can be updated if they ever fail. It should make the query you want simpler as well.

Last edited by Wired; May 21 '04 at 12:21 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 21 '04, 01:47 PM (#3)
smoseley is online now
WDF Moderator
 
smoseley's Avatar
 
Join Date: March 2003
Location: Miami, FL
Posts: 8,719
smoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud ofsmoseley has much to be proud of
Quote:
Originally Posted by toadeny
I am looking for a way in MS Access SQL to bring up the top 5 employees who have never failed a test, and if they have failed, they will not be shown on this list.
Ok. This requires subqueries (FUN !!!)
Code:
SELECT TOP 5
  e.*,
  p.PassedTests,
  f.FailedTests
FROM
  EMPLOYEE AS e
  INNER JOIN
    (SELECT e.EmployeeId, COUNT(h.TestID) AS PassedTests
    FROM EMPLOYEE AS e
      INNER JOIN HISTORY AS h ON e.EmployeeId = h.EmployeeId
    WHERE h.Passed = 1
    GROUP BY e.EmployeeId
    ) AS p ON e.EmployeeId = p.EmployeeId
  INNER JOIN
    (SELECT e.EmployeeId, COUNT(h.TestID) AS FailedTests
    FROM EMPLOYEE AS e
      INNER JOIN HISTORY AS h ON e.EmployeeId = h.EmployeeId
    WHERE h.Passed = 0
    GROUP BY e.EmployeeId
    ) AS f ON e.EmployeeId = f.EmployeeId
WHERE f.FailedTests = 0
ORDER BY p.PassedTests DESC
The other one will be similar... you can figure it out, I'm sure?

Last edited by smoseley; May 21 '04 at 01:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » Database Systems Help

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:02 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164