Solved

Help me  please sql query

Posted on 2013-12-06
3
230 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now