[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help me  please sql query

Posted on 2013-12-06
3
Medium Priority
?
243 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 120

Accepted Solution

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

Assisted Solution

by:Tony303
Tony303 earned 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

873 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