这是我的问题:
SELECT * FROM OPENQUERY(MyLinkedServer,'SELECT * FROM MyDB.schema_name.Table')
以下是我使用的表格:
attendance_tbl: http://prntscr.com/j21rib
它存储学生每天的入学录入某个课程,房间,部分
status_tbl: http://prntscr.com/j21ro8
状态表包含出勤表中的status_id图例
student_tbl: http://prntscr.com/j21spa
它包含学生的学号,姓名等
announcement_tbl: http://prntscr.com/j21s5h
它存储公告,如果描述是假日,它将不计算学生在该特定日期的出勤率。
我的问题是它没有返回任何行。在我的公告表上,如屏幕上限所示,日期表示2018年3月24日的假期。所有在该日期的出勤都不得计算在内。因此,必须显示2018年3月25日的剩余2个数据,因为它不是假日。你可以帮我解释为什么它没有返回任何数据吗?
答案 0 :(得分:0)
好的我可能会有一些东西,因为我说这个查询非常复杂,所以我认为。
无论如何,我把它全部搞砸了,所以它有点可读
SELECT
s.student_id as 'Student_Number',
CONCAT(
IFNULL(s.student_fname,''),
' ',
IFNULL(s.student_mname,''),
' ',
FNULL(s.student_lname,'')
) 'Student_Name',
s.student_program as 'Program',
(SUM(IF(stat.status_description='Late',1,0))) 'Total_Lates',
(SUM(IF(stat.status_description='Absent',1,0))) 'Total_Absences',
Floor((SUM(IF(stat.status_description='Late',1,0))) / 3 + (SUM(IF(stat.status_description='Absent',1,0)))) 'Total_Absence_with_Lates'
FROM
attendance_tbl a
LEFT JOIN
student_tbl s ON s.student_id=a.entity_id
LEFT JOIN
status_tbl stat ON stat.status_id=a.status_id
left join
announcement_tbl ann on ann.announcement_date=a.date
where
a.course_id='SS019'
and
a.entity_type='Student'
and
CONCAT(IFNULL(s.student_fname,''),' ', IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,''))
and
a.date!=ann.announcement_date
and
ann.announcement_description!='holiday'
GROUP BY
a.entity_id, CONCAT(IFNULL(s.student_fname,''),' ', IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,''))
order by
Student_Name A
我不知道这是什么意思。
and
CONCAT(IFNULL(s.student_fname,''),' ', IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,''))
and
但是如果所有这些都是null,它们只会连接空的空格,它不会匹配数据库中的任何内容,我使用此查询进行了测试。
CREATE TABLE test(
foo VARCHAR(1),
bar VARCHAR(1)
);
INSERT INTO test (foo)VALUES('a');
SELECT * FROM test WHERE CONCAT(IFNULL(bar,''),' ');
你可以在这个小提琴中看到它
https://www.db-fiddle.com/f/9512ewbrSQjLC41tY3chrx/0
当然,这些和条件中的任何一个都可能是错误的,它不会返回结果。没有小提琴和一些样本数据,这是我能做的最好的事情。