Запрос к содержательному отчету - PullRequest
1 голос
/ 19 января 2012

Пример результатов запроса

 Employee_Last   Employee_First   RoleName   CourseName   CourseStart   CourseEnd   Attended  
 Ables           Christopher      ServiceMGR OTC Training 12/1/11       12/1/11     Yes  
 Ables           Christopher      ServiceMGR                                        No
 Ables           Christopher      ServiceMGR OTC Part 1   12/5/11       12/5/11     Yes  
 Ables           Christopher      AssetShipper                                      No  
 Ables           Christopher      AssetShipper                                      No  
 Ables           Christopher      AssetShipper                                      No  
 Ables           Christopher      AssetShipper                                      No  

Это результаты, которые я получаю из запроса, есть много запросов, которые извлекают из таблиц эти данные. База данных нормализована.
Отчет, который я собираюсь создать, - это то, на что я обращаю внимание.

 If Yes 
          Show all of the line item from the query 
 Else If   
          If RoleName is listed previously for a specific employee and attended =  
             yes on that line item(ie: Ables | Christopher | ServiceMGR | No -- should not be seen)  
             Don't Show 
          Else If RoleName is listed previously for a specific employee and Attended = No  
             Only Show the item once(ie: Should only see Ables | Christopher | AssetShipper | No)  
          End If  
 End IF

Так что, вероятно, потребуется другой запрос, который фильтрует этот запрос. Отчет, который я ищу по образцу данных, должен выглядеть так:

 Employee_Last   Employee_First   RoleName   CourseName   CourseStart   CourseEnd   Attended  
 Ables           Christopher      ServiceMGR OTC Training 12/1/11       12/1/11     Yes  
 Ables           Christopher      ServiceMGR OTC Part 1   12/5/11       12/5/11     Yes  
 Ables           Christopher      AssetShipper                                      No  

Надеюсь, вы понимаете, о чем я говорю. Я провел некоторые исследования о том, как скрыть и отобразить записи, но я недостаточно знаком с Access. Поэтому в основном мне нужно отфильтровать Attended = No, чтобы иметь смысл для конечного пользователя.

1 Ответ

2 голосов
/ 19 января 2012

Возможно, что-то в этих строках:

SELECT employee_last,
       employee_first,
       rolename,
       coursename,
       coursestart,
       courseend,
       attended
FROM   attend
WHERE  attended = "Yes"
UNION
SELECT DISTINCT b.employee_last,
                b.employee_first,
                b.rolename,
                NULL AS coursename,
                NULL AS coursestart,
                NULL AS courseend,
                b.attended
FROM   (SELECT employee_last,
               employee_first,
               rolename
        FROM   attend
        WHERE  attended = "Yes") AS a
       RIGHT JOIN (SELECT employee_last,
                          employee_first,
                          rolename,
                          attended
                   FROM   attend
                   WHERE  attended = "No") AS b
         ON ( a.rolename = b.rolename )
            AND ( a.employee_first = b.employee_first )
            AND ( a.employee_last = b.employee_last )
WHERE  (( ( a.employee_last ) IS NULL )) 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...