Solved

Help me  please sql query

Posted on 2013-12-06
3
231 Views
Last Modified: 2013-12-06
Please help

I have a table with the following information. As you can see that John Smith was checked 6 times, 2 times out of 6 he made errors, and only one was Critical.

DateProcessed      BundleCount      NumberQCed      ErrorsDesc      CriticalNonCritical      ProcessedBy
10/29/2013      97      1      No Errors      n/a      John Smith
10/31/2013      68      1      No Errors      n/a      John Smith
11/1/2013      30      1      No Errors      n/a      John Smith
11/14/2013      1      1      Error 1      Yes      John Smith
11/14/2013      1      1      Error 2      No      John Smith
10/24/2013      5      1      No Errors      n/a      John Smith

So i would like to have output like
Name         Total          ErrorsOnly         Critical
John Smith 6                2                         1
Test.accdb
0
Comment
Question by:rfedorov
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 400 total points
ID: 39702319
test this, run Query1
Test.accdb
0
 
LVL 12

Assisted Solution

by:Tony303
Tony303 earned 100 total points
ID: 39702320
Here is a working example on your data...

CREATE TABLE #Test
(DateProcessed Date NULL,
BundleCount int NULL,
NumberQCed int NULL,
ErrorsDesc VARCHAR(10) NULL,
CriticalNonCritical VARCHAR(10) NULL,
ProcessedBy VARCHAR(30) NULL)


INSERT INTO #Test (DateProcessed,BundleCount,NumberQCed,ErrorsDesc, CriticalNonCritical,ProcessedBy)
Values ('10/29/2013', 97 ,1 ,'No Errors','n/a', 'John Smith'),
('10/31/2013',      68 ,     1  ,    'No Errors' ,    'n/a',      'John Smith'),
('11/1/2013',    30  ,    1  ,    'No Errors',      'n/a',      'John Smith'),
('11/14/2013',      1,        1,      'Error 1' ,     'Yes',     'John Smith'),
('11/14/2013' ,     1,      1    ,  'Error 2'   ,   'No'     , 'John Smith'),
('10/24/2013',      5 ,     1     , 'No Errors'  ,    'n/a'   ,   'John Smith')

SELECT *
FROM #Test

SELECT ProcessedBy, SUM(Total) AS Total, SUM(ErrorsOnly) AS ErrorsOnly, SUM(Critical) AS Critical
FROM
(
SELECT ProcessedBy, COUNT(*) AS Total,
CASE WHEN ErrorsDesc <> 'No Errors' THEN 1 ELSE 0 END AS ErrorsOnly,
CASE WHEN CriticalNonCritical = 'Yes' THEN 1 ELSE 0 END AS Critical
FROM #Test
GROUP BY ProcessedBy,ErrorsDesc, CriticalNonCritical
) a
GROUP BY a.ProcessedBy

Open in new window

0
 

Author Closing Comment

by:rfedorov
ID: 39702350
Thank you guys,
capricorn1 ---you are the best!!
 Tony303 ---it will take some time to understand!!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now