Solved

Help me  please sql query

Posted on 2013-12-06
3
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

730 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