我被困住了,需要建议。 这可能很简单,但是,我是初学者并尽快学习,所以请耐心等待。 我有一个包含“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
答案 0 :(得分: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