我的两个 SQL 查询如下:-
1)
SELECT Pk_class_id
FROM tbl_student
JOIN tbl_class on tbl_student.fk_class_id = tbl_class.pk_class_id
JOIN tbl_staff on tbl_staff.Pk_staff_id = tbl_class.fk_staff_id
WHERE tbl_student.updated_at <= now() - INTERVAL 30 DAY
2)
SELECT Pk_class_id
FROM tbl_student
JOIN tbl_class on tbl_student.fk_class_id = tbl_class.pk_class_id
JOIN tbl_staff on tbl_staff.Pk_staff_id = tbl_class.fk_staff_id
WHERE tbl_staff.reg_time >= tbl_student.updated_at - INTERVAL 1 MINUTE
两个查询都运行没有错误,而我需要将其变成一个查询,例如(1+!2) 我需要与第二个查询相反的查询与第一个查询相关联。
我试图得到第二个查询的相反结果,如下所示: -
SELECT Pk_class_id
FROM tbl_student
JOIN tbl_class on tbl_student.fk_class_id = tbl_class.pk_class_id
JOIN tbl_staff on tbl_staff.Pk_staff_id = tbl_class.fk_staff_id
WHERE tbl_staff.reg_time
**NOT IN**
(
SELECT Pk_class_id
FROM tbl_student
JOIN tbl_class on tbl_student.fk_class_id = tbl_class.pk_class_id
JOIN tbl_staff on tbl_staff.Pk_staff_id = tbl_class.fk_staff_id
WHERE tbl_staff.reg_time >= tbl_student.updated_at -INTERVAL 1 MINUTE
)
结果:错误 1241 (21000):操作数应包含 1 列
有什么建议可以得到第二个查询的相反结果并与第一个查询结合吗?
任何一段代码表示赞赏并提前感谢。