-1

我被困住了,需要建议。这可能很简单,但是,我是这里的初学者,并试图尽快学习,所以请多多包涵。我有一个包含“A”/“P”格式的考勤数据的表格。我试图在报告中显示一个班级中有多少人在某个日期范围内错过了三次或更多次。在大多数情况下,我让 SQL 语句完成所有工作,但有一个例外。我可以显示某人错过了多少次的总和,但我无法弄清楚如何仅显示缺勤超过 3 次的学生。我在我希望数据返回的列的表达式中输入以下内容:

=SUM(IIF(Fields!Attendance.Value ="A",1,NOTHING))

如果我这样写表达式:

=SUM(IIF(Fields!Attendance.Value ="A",1,NOTHING))>=3

我得到 TRUE/FALSE 回报。如果我能弄清楚如何只显示 TRUE 返回,那就没问题了。

任何建议表示赞赏!

我的整个 SQL 语句 - 还有另外两个数据集被调用以将数据拉入这个数据集。

SELECT     smgp_group.group_id
    , smgp_group.group_name
    , core_v_person_basic.last_name + ', ' + core_v_person_basic.nick_name as Name
    , core_v_person_basic.birth_date AS Birthdate
    , '*' + CONVERT(varchar, core_v_person_basic.person_id) + '*' AS person_id
    , core_v_person_basic.street_address_1
    , core_v_person_basic.city + ',' + core_v_person_basic.state + ' ' + core_v_person_basic.postal_code AS Citystatezip
    , core_v_person_basic.home_phone
    , core_v_person_basic.email
    , core_lookup.lookup_value AS [Group Role]
    , CATD.occurrence_end_time
    , CATD.Attendance as attendance
    , MAX(CATD.DateLastAttended) AS Datelastattended
    , CATD.occurrence_end_time AS [Start Date]
    , CATD.occurrence_end_time AS [End Date]
    , '*$' + CONVERT(varchar, CATD.occurrence_id) + '*' AS 'occurrence_id'
    , core_v_person_basic.cell_phone
FROM smgp_group 
    INNER JOIN cust_v_attendanceroll AS CATD 
    INNER JOIN core_lookup ON CATD.role_luid = core_lookup.lookup_id 
    INNER JOIN core_v_person_basic ON CATD.person_id = core_v_person_basic.person_id ON smgp_group.group_id = CATD.group_id
where CATD.occurrence_end_time between @startdate AND @enddate and smgp_group.group_id IN (@group)
GROUP BY smgp_group.group_id, smgp_group.group_name, core_v_person_basic.last_name,core_v_person_basic.nick_name, core_v_person_basic.birth_date, core_v_person_basic.street_address_1, 
                      core_v_person_basic.city + ',' + core_v_person_basic.state + ' ' + core_v_person_basic.postal_code, core_v_person_basic.home_phone, 
                      core_v_person_basic.email, core_lookup.lookup_value, CATD.occurrence_end_time, CATD.Attendance, CATD.occurrence_id, core_v_person_basic.person_id, 
                      core_v_person_basic.cell_phone
HAVING attendance = 'A' 
ORDER BY attendance
4

1 回答 1

0

想试试这个吗?

SideTrack:您可能需要检查:两者[Start Date][End Date]都设置为CATD.occurrence_end_time

SELECT      *
FROM        (
        SELECT      smgp_group.group_id
                , smgp_group.group_name
                , core_v_person_basic.last_name + ', ' + core_v_person_basic.nick_name as Name
                , core_v_person_basic.birth_date AS Birthdate
                , '*' + CONVERT(varchar, core_v_person_basic.person_id) + '*' AS person_id
                , core_v_person_basic.street_address_1
                , core_v_person_basic.city + ',' + core_v_person_basic.state + ' ' + core_v_person_basic.postal_code AS Citystatezip
                , core_v_person_basic.home_phone
                , core_v_person_basic.email
                , core_lookup.lookup_value AS [Group Role]
                , CATD.occurrence_end_time
                , MAX(CATD.DateLastAttended) AS Datelastattended
                , CATD.occurrence_end_time AS [Start Date]
                , CATD.occurrence_end_time AS [End Date]
                , '*$' + CONVERT(varchar, CATD.occurrence_id) + '*' AS 'occurrence_id'
                , core_v_person_basic.cell_phone

                , COUNT(*) AS absentCount

        FROM        smgp_group 
                INNER JOIN cust_v_attendanceroll AS CATD 
                INNER JOIN core_lookup ON CATD.role_luid = core_lookup.lookup_id 
                INNER JOIN core_v_person_basic ON CATD.person_id = core_v_person_basic.person_id ON smgp_group.group_id = CATD.group_id
        WHERE       CATD.occurrence_end_time BETWEEN @startdate AND @enddate
                AND smgp_group.group_id IN (@group)
                AND CATD.Attendance = 'A'
        GROUP BY    smgp_group.group_id, smgp_group.group_name, core_v_person_basic.last_name,core_v_person_basic.nick_name, core_v_person_basic.birth_date, core_v_person_basic.street_address_1, 
                core_v_person_basic.city + ',' + core_v_person_basic.state + ' ' + core_v_person_basic.postal_code, core_v_person_basic.home_phone, 
                core_v_person_basic.email, core_lookup.lookup_value, CATD.occurrence_end_time, CATD.occurrence_id, core_v_person_basic.person_id, 
                core_v_person_basic.cell_phone
        ) AS tblSource
WHERE       absentCount>=3
于 2013-03-18T20:12:03.137 回答